Guest User

Untitled

a guest
Feb 20th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. require "rubygems"
  2. require "json"
  3.  
  4. tohle_je_json_z_fajlu = <<HEREDOC
  5. {
  6. "disp": "nejaky text",
  7. "platforma": [
  8. {
  9. "ido": 1,
  10. "jmeno": "prvni",
  11. "priorita": 3,
  12. "mountpoints": [1,3,4]
  13. },{
  14. "ido": 1,
  15. "jmeno": "druha",
  16. "priorita": 3,
  17. "mountpoints": [1,3,4]
  18. }
  19. ]
  20. }
  21. HEREDOC
  22.  
  23. o = JSON.parse(tohle_je_json_z_fajlu)
  24. puts o.inspect
  25.  
  26. module PlatformyMixin
  27.  
  28. def platforma # tento getter by mel byt autogenerovany
  29. self['platforma']
  30. end
  31.  
  32. def jmena_platforem
  33. platforma.map{|o| o['jmeno'] }.sort!
  34. end
  35. end
  36.  
  37. o.extend(PlatformyMixin)
  38.  
  39. puts o.jmena_platforem
Add Comment
Please, Sign In to add comment