Class: LinkThumbnailer::Object

Inherits:
Hashie::Mash
  • Object
show all
Defined in:
lib/link_thumbnailer/object.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/link_thumbnailer/object.rb', line 7

def method_missing(method_name, *args, &block)
  method_name = method_name.to_s

  if method_name.end_with?('?')
    method_name.chop!
    !self[method_name].nil?
  else
    self[method_name]
  end
end

Instance Method Details

#to_hashObject



24
25
26
27
28
29
30
# File 'lib/link_thumbnailer/object.rb', line 24

def to_hash
  if self.images.none? {|i| i.is_a?(String)}
    super.merge('images' => self.images.map(&:to_hash))
  else
    super
  end
end

#to_jsonObject



32
33
34
35
36
37
38
# File 'lib/link_thumbnailer/object.rb', line 32

def to_json
  if self.images.none? {|i| i.is_a?(String)}
    JSON.generate(self.to_hash.merge('images' => self.images.map(&:to_hash)))
  else
    JSON.generate(self.to_hash)
  end
end

#valid?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/link_thumbnailer/object.rb', line 18

def valid?
  return false if self.keys.empty?
  LinkThumbnailer.configuration.mandatory_attributes.each {|a| return false if self[a].nil? || self[a].empty? } if LinkThumbnailer.configuration.strict
  true
end