Class: W3cApi::Models::Participation

Inherits:
Base
  • Object
show all
Defined in:
lib/w3c_api/models/participation.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

transform_keys

Class Method Details

.from_response(response) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/w3c_api/models/participation.rb', line 90

def self.from_response(response)
  transformed_response = transform_keys(response)

  participation = new
  transformed_response.each do |key, value|
    case key
    when :_links
      links = value.each_with_object({}) do |(link_name, link_data), acc|
        acc[link_name] = Link.new(href: link_data[:href], title: link_data[:title])
      end
      participation._links = ParticipationLinks.new(links)
    else
      participation.send("#{key}=", value) if participation.respond_to?("#{key}=")
    end
  end
  participation
end

Instance Method Details

#created_dateObject

Parse date strings to Date objects



48
49
50
51
52
# File 'lib/w3c_api/models/participation.rb', line 48

def created_date
  Date.parse(created) if created
rescue Date::Error
  nil
end

#group(client = nil) ⇒ Object

Get the group this participation is for



55
56
57
58
59
60
61
# File 'lib/w3c_api/models/participation.rb', line 55

def group(client = nil)
  return nil unless client && _links&.group

  href = _links.group.href
  id = href.split('/').last
  client.group(id)
end

#organization(client = nil) ⇒ Object

Get the organization participating



73
74
75
76
77
78
79
# File 'lib/w3c_api/models/participation.rb', line 73

def organization(client = nil)
  return nil unless client && _links&.organization

  href = _links.organization.href
  id = href.split('/').last
  client.affiliation(id)
end

#participants(client = nil) ⇒ Object

Get participants in this participation



82
83
84
85
86
87
88
# File 'lib/w3c_api/models/participation.rb', line 82

def participants(client = nil)
  return nil unless client && _links&.participants

  href = _links.participants.href
  id = href.split('/').last
  client.participation_participants(id)
end

#user(client = nil) ⇒ Object

Get the user participating



64
65
66
67
68
69
70
# File 'lib/w3c_api/models/participation.rb', line 64

def user(client = nil)
  return nil unless client && _links&.user

  href = _links.user.href
  id = href.split('/').last
  client.user(id)
end