Class: Tvdbr::DataSet

Inherits:
Hashie::Mash
  • Object
show all
Defined in:
lib/tvdbr/data_set.rb

Direct Known Subclasses

Episode, Series

Defined Under Namespace

Classes: InvalidFormat

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, source_hash = nil, default = nil, &block) ⇒ DataSet

Tvdb::DataSet.new(self, { :foo => “bar” })



12
13
14
15
16
17
18
# File 'lib/tvdbr/data_set.rb', line 12

def initialize(parent, source_hash = nil, default = nil, &block)
  @parent = parent
  source_hash = normalize_keys(source_hash) if source_hash.is_a?(Hash)
  super(source_hash, default, &block)
rescue ArgumentError => e # #<ArgumentError: wrong number of arguments (0 for 1)>
  raise InvalidFormat, "#{self.class.name} parse failed with source #{source_hash.inspect}"
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



7
8
9
# File 'lib/tvdbr/data_set.rb', line 7

def parent
  @parent
end

Class Method Details

.absolutize(*attrs) ⇒ Object

Turns a relative image link to a full tvdb link url absolutize :file_name



56
57
58
59
60
# File 'lib/tvdbr/data_set.rb', line 56

def self.absolutize(*attrs)
  attrs.each do |a|
    define_method(a) { File.join("http://www.thetvdb.com/banners/", self[a]) if self[a] }
  end
end

.alias_property(original, name) ⇒ Object

Aliases the original propery to the new method name alias_property :old, :new



34
35
36
# File 'lib/tvdbr/data_set.rb', line 34

def self.alias_property(original, name)
  define_method(name) { self.send(original) }
end

.dateify(*attrs) ⇒ Object

Turns a property into a date object dateify :release_date



48
49
50
51
52
# File 'lib/tvdbr/data_set.rb', line 48

def self.dateify(*attrs)
  attrs.each do |a|
    define_method(a) { Time.parse(self[a]) rescue nil if self[a] }
  end
end

.listify(*attrs) ⇒ Object

Turns a property “a | b | c” => [‘a’, ‘b’, ‘c’] listify :lista, :listb



40
41
42
43
44
# File 'lib/tvdbr/data_set.rb', line 40

def self.listify(*attrs)
  attrs.each do |a|
    define_method(a) { self[a] ? self[a][1..-1].split("|").map(&:strip) : []  }
  end
end

Instance Method Details

#inspectObject

Outputs: <#Tvdb::Series actors=“…” added=nil added_by=nil>



21
22
23
24
25
26
27
28
# File 'lib/tvdbr/data_set.rb', line 21

def inspect
  ret = "<##{self.class.to_s}"
  self.keys.sort.each do |key|
    ret << " #{key}=#{self[key].inspect}"
  end
  ret << ">"
  ret
end