Class: Everypolitician::Popolo::Entity

Inherits:
Object
  • Object
show all
Defined in:
lib/everypolitician/popolo/entity.rb

Direct Known Subclasses

Area, Event, Membership, Organization, Person, Post

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ Entity

Returns a new instance of Entity.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/everypolitician/popolo/entity.rb', line 8

def initialize(document)
  @document = document

  document.each do |key, value|
    if respond_to?("#{key}=")
      __send__("#{key}=", value)
    else
      define_singleton_method(key) { value }
    end
  end
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



6
7
8
# File 'lib/everypolitician/popolo/entity.rb', line 6

def document
  @document
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/everypolitician/popolo/entity.rb', line 5

def id
  @id
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



28
29
30
# File 'lib/everypolitician/popolo/entity.rb', line 28

def ==(other)
  id == other.id
end

#[](key) ⇒ Object



20
21
22
# File 'lib/everypolitician/popolo/entity.rb', line 20

def [](key)
  document[key]
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/everypolitician/popolo/entity.rb', line 24

def key?(key)
  document.key?(key)
end