123456789_123456789_123456789_123456789_123456789_

Class: RSS::ITunesItemModel::ITunesDuration

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: RSS::Element
Defined in: lib/rss/itunes.rb

Constant Summary

::RSS::Element - Inherited

GET_ATTRIBUTES, HAVE_CHILDREN_ELEMENTS, INDENT, MODELS, MUST_CALL_VALIDATORS, NEED_INITIALIZE_VARIABLES, PLURAL_FORMS, TO_ELEMENT_METHODS

::RSS::RSS09 - Included

ELEMENTS, NSPOOL

Class Attribute Summary

Class Method Summary

::RSS::Element - Inherited

::RSS::Utils::InheritedReader - Extended

::RSS::BaseModel - Extended

::RSS::Utils - Included

element_initialize_arguments?

This method is used inside of several different objects to determine if special behavior is needed in the constructor.

get_file_and_line_from_caller

Returns an array of two elements: the filename where the calling method is located, and the line number where it is defined.

h,
html_escape

Takes a string s with some HTML in it, and escapes '&', '“', '<' and '>', by replacing them with the appropriate entities.

new_with_value_if_need

If #value is an instance of class klass, return it, else create a new instance of klass with value #value.

to_class_name

Given a name in a name_with_underscores or a name-with-dashes format, returns the CamelCase version of name.

Instance Attribute Summary

Instance Method Summary

::RSS::Element - Inherited

::RSS::SetupMaker - Included

::RSS::Utils - Included

#element_initialize_arguments?

This method is used inside of several different objects to determine if special behavior is needed in the constructor.

#get_file_and_line_from_caller

Returns an array of two elements: the filename where the calling method is located, and the line number where it is defined.

#h,
#html_escape

Takes a string s with some HTML in it, and escapes '&', '“', '<' and '>', by replacing them with the appropriate entities.

#new_with_value_if_need

If #value is an instance of class klass, return it, else create a new instance of klass with value #value.

#to_class_name

Given a name in a name_with_underscores or a name-with-dashes format, returns the CamelCase version of name.

Constructor Details

.new(*args) ⇒ ITunesDuration

[ GitHub ]

  
# File 'lib/rss/itunes.rb', line 314

def initialize(*args)
  if Utils.element_initialize_arguments?(args)
    super
  else
    super()
    args = args[0] if args.size == 1 and args[0].is_a?(Array)
    if args.size == 1
      self.content = args[0]
    elsif args.size > 3
      raise ArgumentError,
              "must be (do_validate, params), (content), " +
              "(minute, second), ([minute, second]), "  +
              "(hour, minute, second) or ([hour, minute, second]): " +
              args.inspect
    else
      @second, @minute, @hour = args.reverse
      update_content
    end
  end
end

Class Method Details

.construct(hour, minute, second)

[ GitHub ]

  
# File 'lib/rss/itunes.rb', line 296

def construct(hour, minute, second)
  components = [minute, second]
  if components.include?(nil)
    nil
  else
    components.unshift(hour) if hour and hour > 0
    components.collect do |component|
      "%02d" % component
    end.join(":")
  end
end

.parse(duration, do_validate = true)

[ GitHub ]

  
# File 'lib/rss/itunes.rb', line 276

def parse(duration, do_validate=true)
  if do_validate and /\A(?:
                          \d?\d:[0-5]\d:[0-5]\d|
                          [0-5]?\d:[0-5]\d
                        )\z/x !~ duration
    raise ArgumentError,
            "must be one of HH:MM:SS, H:MM:SS, MM::SS, M:SS: " +
            duration.inspect
  end

  components = duration.split(':')
  components[3..-1] = nil if components.size > 3

  components.unshift("00") until components.size == 3

  components.collect do |component|
    component.to_i
  end
end

.required_prefix

[ GitHub ]

  
# File 'lib/rss/itunes.rb', line 268

def required_prefix
  ITUNES_PREFIX
end

.required_uri

[ GitHub ]

  
# File 'lib/rss/itunes.rb', line 272

def required_uri
  ITUNES_URI
end

Instance Attribute Details

#content=(value) (writeonly) Also known as: #value=

[ GitHub ]

  
# File 'lib/rss/itunes.rb', line 335

def content=(value)
  if value.nil?
    @content = nil
  elsif value.is_a?(self.class)
    self.content = value.content
  else
    begin
      @hour, @minute, @second = self.class.parse(value, @do_validate)
    rescue ArgumentError
      raise NotAvailableValueError.new(tag_name, value)
    end
    @content = value
  end
end

#hour (rw)

[ GitHub ]

  
# File 'lib/rss/itunes.rb', line 313

attr_reader :hour, :minute, :second

#hour=(hour) (rw)

[ GitHub ]

  
# File 'lib/rss/itunes.rb', line 351

def hour=(hour)
  @hour = @do_validate ? Integer(hour) : hour.to_i
  update_content
  hour
end

#minute (rw)

[ GitHub ]

  
# File 'lib/rss/itunes.rb', line 313

attr_reader :hour, :minute, :second

#minute=(minute) (rw)

[ GitHub ]

  
# File 'lib/rss/itunes.rb', line 357

def minute=(minute)
  @minute = @do_validate ? Integer(minute) : minute.to_i
  update_content
  minute
end

#second (rw)

[ GitHub ]

  
# File 'lib/rss/itunes.rb', line 313

attr_reader :hour, :minute, :second

#second=(second) (rw)

[ GitHub ]

  
# File 'lib/rss/itunes.rb', line 363

def second=(second)
  @second = @do_validate ? Integer(second) : second.to_i
  update_content
  second
end

Instance Method Details

#full_name

[ GitHub ]

  
# File 'lib/rss/itunes.rb', line 369

def full_name
  tag_name_with_prefix(ITUNES_PREFIX)
end

#maker_target(target) (private)

[ GitHub ]

  
# File 'lib/rss/itunes.rb', line 378

def maker_target(target)
  if @content
    target.itunes_duration {|duration| duration}
  else
    nil
  end
end

#setup_maker_element(duration) (private)

[ GitHub ]

  
# File 'lib/rss/itunes.rb', line 386

def setup_maker_element(duration)
  super(duration)
  duration.content = @content
end

#update_content (private)

[ GitHub ]

  
# File 'lib/rss/itunes.rb', line 374

def update_content
  @content = self.class.construct(hour, minute, second)
end

#value (writeonly)

[ GitHub ]

  
# File 'lib/rss/itunes.rb', line 310

alias_method(:value, :content)