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, popolo = nil) ⇒ Entity

Returns a new instance of Entity.



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

def initialize(document, popolo = nil)
  @document = document
  @popolo = popolo

  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

#popoloObject (readonly)

Returns the value of attribute popolo.



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

def popolo
  @popolo
end

Instance Method Details

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



30
31
32
# File 'lib/everypolitician/popolo/entity.rb', line 30

def ==(other)
  self.class == other.class && id == other.id
end

#[](key) ⇒ Object



22
23
24
# File 'lib/everypolitician/popolo/entity.rb', line 22

def [](key)
  document[key]
end

#identifier(scheme) ⇒ Object



35
36
37
# File 'lib/everypolitician/popolo/entity.rb', line 35

def identifier(scheme)
  identifiers.find(->{{}}) { |i| i[:scheme] == scheme }[:identifier]
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/everypolitician/popolo/entity.rb', line 26

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