Class: Tvdbr::DataSet
- Inherits:
-
Hashie::Mash
- Object
- Hashie::Mash
- Tvdbr::DataSet
- Defined in:
- lib/tvdbr/data_set.rb
Defined Under Namespace
Classes: InvalidFormat
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Class Method Summary collapse
-
.absolutize(*attrs) ⇒ Object
Turns a relative image link to a full tvdb link url absolutize :file_name.
-
.alias_property(original, name) ⇒ Object
Aliases the original propery to the new method name alias_property :old, :new.
-
.dateify(*attrs) ⇒ Object
Turns a property into a date object dateify :release_date.
-
.listify(*attrs) ⇒ Object
Turns a property “a | b | c” => [‘a’, ‘b’, ‘c’] listify :lista, :listb.
Instance Method Summary collapse
-
#initialize(parent, source_hash = nil, default = nil, &block) ⇒ DataSet
constructor
Tvdb::DataSet.new(self, { :foo => “bar” }).
-
#inspect ⇒ Object
Outputs: <#Tvdb::Series actors=“…” added=nil added_by=nil>.
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
#parent ⇒ Object (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
#inspect ⇒ Object
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 |