Class: RichSnippet::CreativeWork
- Defined in:
- app/models/rich_snippet/creative_work.rb
Instance Method Summary collapse
Methods inherited from Thing
#array_json, #module, #name, #type, #warnings
Instance Method Details
#to_json(render_childs = false) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/models/rich_snippet/creative_work.rb', line 41 def to_json(render_childs = false) json = { "@context": "http://schema.org", "@type": "CreativeWork", name: name, description: description, image: image ? image.binary_url : nil, url: url, about: about, author: ? .to_json : nil, contributor: contributor ? contributor.to_json : nil, copyrightHolder: copyright_holder ? copyright_holder.to_json : nil, copyrightYear: copyright_year, dateCreated: date_created, datePublished: date_published, genre: genre, inLanguage: in_language, isAccessibleForFree: is_accessible_for_free == 'Yes', isBasedOn: is_based_on ? is_based_on.to_json: nil, isFamilyFriendly: is_family_friendly == 'Yes', license: license, offers: array_json(offers), position: position, publisher: publisher ? publisher.to_json : nil, thumbnailUrl: thumbnail_url, typicalAgeRange: typical_age_range, } if work_type == 'Book' json[:illustrator] = illustrator ? illustrator.to_json : nil json[:isbn] = isbn json[:numberOfPage] = number_of_page elsif work_type == 'Movie' json[:actors] = array_json(actors) json[:director] = director ? director.to_json : nil json[:duration] = duration elsif work_type == 'WebPage' json[:breadcrumb] = Obj.repson_to?('page_breadcrumb') ? obj. : elsif work_type == 'MusicComposition' json[:composer] = composer ? composer.to_json : nil json[:lyricist] = lyricist ? lyricist.to_json : nil json[:lyrics] = lyrics end return json.delete_if { |k, v| !v.present? } end |