Class: W3cApi::Models::Charter
- Defined in:
- lib/w3c_api/models/charter.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#active? ⇒ Boolean
Check if this charter is active.
-
#end_date ⇒ Object
Parse date strings to Date objects.
-
#extended? ⇒ Boolean
Check if this charter has been extended.
-
#group(client = nil) ⇒ Object
Return the group this charter belongs to.
- #initial_end_date ⇒ Object
- #start_date ⇒ Object
Methods inherited from Base
Class Method Details
.from_response(response) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/w3c_api/models/charter.rb', line 91 def self.from_response(response) transformed_response = transform_keys(response) charter = 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 charter._links = CharterLinks.new(links) else charter.send("#{key}=", value) if charter.respond_to?("#{key}=") end end charter end |
Instance Method Details
#active? ⇒ Boolean
Check if this charter is active
78 79 80 81 82 83 84 |
# File 'lib/w3c_api/models/charter.rb', line 78 def active? start_date && (end_date.nil? || end_date >= Date.today) && start_date <= Date.today rescue Date::Error false end |
#end_date ⇒ Object
Parse date strings to Date objects
59 60 61 62 63 |
# File 'lib/w3c_api/models/charter.rb', line 59 def end_date Date.parse(self.end) if self.end rescue Date::Error nil end |
#extended? ⇒ Boolean
Check if this charter has been extended
87 88 89 |
# File 'lib/w3c_api/models/charter.rb', line 87 def extended? !extensions.nil? && !extensions.empty? end |
#group(client = nil) ⇒ Object
Return the group this charter belongs to
49 50 51 52 53 54 55 56 |
# File 'lib/w3c_api/models/charter.rb', line 49 def group(client = nil) return nil unless client && _links&.group group_href = _links.group.href group_id = group_href.split('/').last client.group(group_id) end |
#initial_end_date ⇒ Object
71 72 73 74 75 |
# File 'lib/w3c_api/models/charter.rb', line 71 def initial_end_date Date.parse(initial_end) if initial_end rescue Date::Error nil end |
#start_date ⇒ Object
65 66 67 68 69 |
# File 'lib/w3c_api/models/charter.rb', line 65 def start_date Date.parse(start) if start rescue Date::Error nil end |