Class: BibleQL::Resource
- Inherits:
-
Object
show all
- Defined in:
- lib/bibleql/resource.rb
Instance Method Summary
collapse
Constructor Details
#initialize(attributes = {}) ⇒ Resource
Returns a new instance of Resource.
5
6
7
8
9
10
|
# File 'lib/bibleql/resource.rb', line 5
def initialize(attributes = {})
attributes.each do |key, value|
setter = "#{key}="
public_send(setter, value) if respond_to?(setter)
end
end
|
Instance Method Details
#==(other) ⇒ Object
20
21
22
|
# File 'lib/bibleql/resource.rb', line 20
def ==(other)
other.is_a?(self.class) && to_h == other.to_h
end
|
#to_h ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/bibleql/resource.rb', line 12
def to_h
instance_variables.each_with_object({}) do |ivar, hash|
key = ivar.to_s.delete_prefix("@").to_sym
value = instance_variable_get(ivar)
hash[key] = value.is_a?(Resource) ? value.to_h : value
end
end
|
#to_s ⇒ Object
Also known as:
inspect
24
25
26
|
# File 'lib/bibleql/resource.rb', line 24
def to_s
"#<#{self.class.name} #{to_h.map { |k, v| "#{k}=#{v.inspect}" }.join(", ")}>"
end
|