Class: Pige::Client::Label
- Defined in:
- lib/pige/client/label.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
Attributes inherited from Resource
#created_at, #errors, #id, #source_id, #updated_at
Class Method Summary collapse
- .all(options = {}) ⇒ Object
- .by_name(name, options = {}) ⇒ Object
- .older_than(date) ⇒ Object
- .page(number, options = {}) ⇒ Object
Instance Method Summary collapse
Methods inherited from Resource
base_url, create, #destroy, destroy, destroy_all, #initialize, resource_name, resources_name, time_attribute
Constructor Details
This class inherits a constructor from Pige::Client::Resource
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/pige/client/label.rb', line 3 def name @name end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
3 4 5 |
# File 'lib/pige/client/label.rb', line 3 def @timestamp end |
Class Method Details
.all(options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/pige/client/label.rb', line 10 def self.all( = {}) [].tap do |labels| page = 1 empty_page = false begin labels_in_page = page(page, ) unless labels_in_page.empty? labels.push *labels_in_page page += 1 else empty_page = true end end until empty_page end end |
.by_name(name, options = {}) ⇒ Object
27 28 29 30 31 |
# File 'lib/pige/client/label.rb', line 27 def self.by_name(name, = {}) = .merge(term: name) attributes = get("#{Pige::Client.box_url}/sources/1/labels.json", query: ).first Label.new attributes if attributes end |
.older_than(date) ⇒ Object
33 34 35 |
# File 'lib/pige/client/label.rb', line 33 def self.older_than(date) all(before: date) end |
.page(number, options = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/pige/client/label.rb', line 37 def self.page(number, = {}) additionnal_query = .map do |k,v| "#{k}=#{URI.escape(v.to_s)}" if v end.join('&') additionnal_query = "&#{additionnal_query}" unless additionnal_query.empty? get("#{Pige::Client.box_url}/sources/1/labels.json?page=#{number}#{additionnal_query}").map do |attributes| Label.new attributes end end |
Instance Method Details
#older_than?(date) ⇒ Boolean
6 7 8 |
# File 'lib/pige/client/label.rb', line 6 def older_than?(date) self. < date end |