Class: UncleKryon::Jsoner
- Inherits:
-
Object
- Object
- UncleKryon::Jsoner
- Defined in:
- lib/unclekryon/jsoner.rb
Instance Method Summary collapse
- #jsonify_all(pretty = false) ⇒ Object
- #jsonify_artist_data(json, artist, file) ⇒ Object
- #jsonify_artists(json) ⇒ Object
- #jsonify_iso(json) ⇒ Object
- #to_hash(obj) ⇒ Object
Instance Method Details
#jsonify_all(pretty = false) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/unclekryon/jsoner.rb', line 23 def jsonify_all(pretty=false) json = {} #jsonify_iso(json) jsonify_artists(json) return pretty ? JSON.pretty_generate(json) : json.to_json end |
#jsonify_artist_data(json, artist, file) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/unclekryon/jsoner.rb', line 50 def jsonify_artist_data(json,artist,file) data = ArtistDataData.load_file(file) data.albums.each do |album_id,album| album.aums.each do |aum_id,aum| json[ArtistDataData::AUMS_ID][aum_id] = to_hash(aum) end album.aums = album.aums.keys album.pics.each do |pic_id,pic| json[ArtistDataData::PICS_ID][pic_id] = to_hash(pic) end album.pics = album.pics.keys end artist[ArtistDataData::ALBUMS_ID] = to_hash(data.albums) #attr_accessor :scrolls #attr_accessor :visions end |
#jsonify_artists(json) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/unclekryon/jsoner.rb', line 32 def jsonify_artists(json) json['aum'] = {} json['scroll'] = {} json['vision'] = {} json['pic'] = {} kryon = to_hash(ArtistData.load_file(File.join('hax','kryon.yaml'))) kryon['release'] = {} kryon['album'] = {} jsonify_artist_data(json,kryon,File.join('hax','kryon_aums_2002-2005.yaml')) json['artist'] = { kryon['id'] => kryon } end |
#jsonify_iso(json) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/unclekryon/jsoner.rb', line 71 def jsonify_iso(json) json['iso'] = to_hash(Iso.iso) json['can_proterr'] = to_hash(Iso.can_provs_terrs.values) json['country'] = to_hash(Iso.countries.values) json['language'] = to_hash(Iso.languages.values) json['region'] = to_hash(Iso.regions.values) json['subregion'] = to_hash(Iso.subregions.values) json['usa_state'] = to_hash(Iso.usa_states.values) end |
#to_hash(obj) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/unclekryon/jsoner.rb', line 81 def to_hash(obj) hash = {} if obj.respond_to?(:instance_variables) && obj.instance_variables.length > 0 obj.instance_variables.each do |var| hash[var.to_s.delete('@')] = to_hash(obj.instance_variable_get(var)) end elsif obj.is_a?(Hash) obj.each do |k,v| hash[k] = to_hash(v) end else return Util.empty_s?(obj.to_s) ? nil : obj end return hash end |