Class: PocketAPI::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/pocket_api/item.rb

Constant Summary collapse

INTEGER_ATTRIBUTES =
%w(favorite status word_count has_video has_image sort_id)
BOOLEAN_ATTRIBUTES =
%w(is_article is_index)
TIME_ATTRIBUTES =
%w(time_added time_updated time_read time_favorited)
STRING_ATTRIBUTES =
%w(item_id resolved_id given_url given_title resolved_title resolved_url excerpt)
ALL_ATTRIBUTES =
INTEGER_ATTRIBUTES | BOOLEAN_ATTRIBUTES | TIME_ATTRIBUTES | STRING_ATTRIBUTES

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Item

Returns a new instance of Item.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/pocket_api/item.rb', line 9

def initialize(hash)
  ALL_ATTRIBUTES.each do |attr_name|
    self.class.send(:define_method, "#{attr_name}=".to_sym) do |val|
      instance_variable_set("@" + attr_name.to_s, val)
    end

    self.class.send(:define_method, attr_name.to_sym) do
      instance_variable_get("@" + attr_name.to_s)
    end

    self.send("#{attr_name}=".to_sym, normalize(attr_name, hash[attr_name]))
  end
end

Instance Method Details

#idObject



23
24
25
# File 'lib/pocket_api/item.rb', line 23

def id
  item_id
end