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
Class Attribute Summary
::RSS::Element
- Inherited
Class Method Summary
- .construct(hours, minutes, seconds)
- .new(*args) ⇒ ITunesDuration constructor
- .parse(duration, do_validate = true)
- .required_prefix
- .required_uri
- .seconds_to_components(total_seconds) private
::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 |
new_with_value_if_need | |
to_class_name | Given a |
Instance Attribute Summary
- #content=(value) (also: #value=) writeonly
- #hour rw
- #hour=(hour) rw
- #minute rw
- #minute=(minute) rw
- #second rw
- #second=(second) rw
::RSS::Element
- Inherited
Instance Method Summary
- #full_name
- #value writeonly
- #maker_target(target) private
- #setup_maker_element(duration) private
- #update_content private
::RSS::Element
- Inherited
::RSS::SetupMaker
- Included
#setup_maker, #maker_target, #not_need_to_call_setup_maker_variables, #setup_maker_attributes, #setup_maker_element, #setup_maker_elements |
::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 |
#new_with_value_if_need | |
#to_class_name | Given a |
Constructor Details
.new(*args) ⇒ ITunesDuration
# File 'lib/rss/itunes.rb', line 375
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(hours, minutes, seconds)
[ GitHub ]# File 'lib/rss/itunes.rb', line 349
def construct(hours, minutes, seconds) components = [minutes, seconds] if components.include?(nil) nil else components.unshift(hours) if hours and hours > 0 components.collect do |component| "%02d" % component end.join(':') end end
.parse(duration, do_validate = true)
[ GitHub ]# File 'lib/rss/itunes.rb', line 325
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| \d+ )\z/x !~ duration raise ArgumentError, "must be one of HH:MM:SS, H:MM:SS, MM:SS, M:SS, S+: " + duration.inspect end if duration.include?(':') 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 else seconds_to_components(duration.to_i) end end
.required_prefix
[ GitHub ]# File 'lib/rss/itunes.rb', line 317
def required_prefix ITUNES_PREFIX end
.required_uri
[ GitHub ]# File 'lib/rss/itunes.rb', line 321
def required_uri ITUNES_URI end
.seconds_to_components(total_seconds) (private)
[ GitHub ]# File 'lib/rss/itunes.rb', line 362
def seconds_to_components(total_seconds) hours = total_seconds / (60 * 60) minutes = (total_seconds / 60) % 60 seconds = total_seconds % 60 [hours, minutes, seconds] end
Instance Attribute Details
#content=(value) (writeonly) Also known as: #value=
[ GitHub ]# File 'lib/rss/itunes.rb', line 396
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 ]#hour=(hour) (rw)
[ GitHub ]# File 'lib/rss/itunes.rb', line 412
def hour=(hour) @hour = @do_validate ? Integer(hour) : hour.to_i update_content hour end
#minute (rw)
[ GitHub ]#minute=(minute) (rw)
[ GitHub ]# File 'lib/rss/itunes.rb', line 418
def minute=(minute) @minute = @do_validate ? Integer(minute) : minute.to_i update_content minute end
#second (rw)
[ GitHub ]#second=(second) (rw)
[ GitHub ]# File 'lib/rss/itunes.rb', line 424
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 430
def full_name tag_name_with_prefix(ITUNES_PREFIX) end
#maker_target(target) (private)
[ GitHub ]# File 'lib/rss/itunes.rb', line 439
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 447
def setup_maker_element(duration) super(duration) duration.content = @content end
#update_content (private)
[ GitHub ]#value (writeonly)
[ GitHub ]# File 'lib/rss/itunes.rb', line 371
alias_method(:value, :content)