Class: RichSnippet::Person

Inherits:
Thing
  • Object
show all
Defined in:
app/models/rich_snippet/person.rb

Instance Method Summary collapse

Methods inherited from Thing

#array_json, #module, #name, #type, #warnings

Instance Method Details

#to_json(render_childs = false) ⇒ Object

[View source]

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
# File 'app/models/rich_snippet/person.rb', line 24

def to_json(render_childs = false)
  json = {
    "@context": "http://schema.org",
    "@type": "Person",
    name: name,
    description: description,
    image: image ? image.binary_url : nil,
    url: url,
    givenName: given_name,
    additionalName: additional_name,
    familyName: family_name,
    address: address ? address.to_json : nil,
    birthDate: birth_date,
    birthPlace: {
      "@context": "http://schema.org",
      "@type": "Place",
      address: birth_place ? birth_place.to_json : nil
    },
    deathDate: death_date,
    "deathPlace": {
      "@context": "http://schema.org",
      "@type": "Place",
      address: death_place ? death_place.to_json : nil
    },
    email: email,
    gender: gender,
    height: height,
    nationality: nationality,
    workLocation: work_location ? work_location.to_json : nil,
    worksFor: works_for ? works_for.to_json : nil,
    telephone: telephone,
    weight: weight
  }

  if(render_childs)
    json[:children] = array_json(children)
    json[:siblings] = array_json(siblings)
    json[:parents] = [
      mother.to_json,
      father.to_json
    ]
  end

  return json.delete_if { |k, v| !v.present? }
end