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.



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

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.



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

def document
  @document
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#popoloObject (readonly)

Returns the value of attribute popolo.



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

def popolo
  @popolo
end

Instance Method Details

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



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

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

#[](key) ⇒ Object



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

def [](key)
  document[key]
end

#identifier(scheme) ⇒ Object



38
39
40
# File 'lib/everypolitician/popolo/entity.rb', line 38

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

#identifiersObject



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

def identifiers
  document.fetch(:identifiers, [])
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


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

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