class ChupaText::Attributes
Attributes
of data.
Public Class Methods
Source
# File lib/chupa-text/attributes.rb, line 26 def initialize super @extra_data = {} end
Public Instance Methods
Source
# File lib/chupa-text/attributes.rb, line 57 def [](name) name = normalize_name(name) if members.include?(name) super else @extra_data[name] end end
Gets the value of attribute named ‘name`.
@param [Symbol, String] name The attribute name. @return [Object] The attribute value.
Source
# File lib/chupa-text/attributes.rb, line 70 def []=(name, value) name = normalize_name(name) if members.include?(name) send("#{name}=", value) else @extra_data[name] = value end end
Sets ‘value` as the value of attribute named `name`.
@param [Symbol, String] name The attribute name. @param [Object] value The attribute value.
Source
# File lib/chupa-text/attributes.rb, line 90 def created_time=(time) super(normalize_time(time)) end
Sets ‘time` as the `created_time` attribute value.
@param [String, Integer, Time, nil] time The created time.
If `time` is `Integer`, it is used as UNIX time.
Source
# File lib/chupa-text/attributes.rb, line 44 def each(&block) if block.nil? Enumerator.new(self, :each) else each_pair(&block) @extra_data.each_pair(&block) end end
@yield [name, value] Gives attribute name and value to the block. @yieldparam [Symbol] name The attribute name. @yieldparam [Object] value The attribute value.
Source
# File lib/chupa-text/attributes.rb, line 82 def encoding=(encoding) super(normalize_encoding(encoding)) end
Sets ‘encoding` as the `encoding` attribute value.
@param [String, Encoding, nil] encoding The encoding.
Source
# File lib/chupa-text/attributes.rb, line 35 def inspect super.gsub(/>\z/) do " @extra_data=#{@extra_data.inspect}>" end end
Source
# File lib/chupa-text/attributes.rb, line 98 def modified_time=(time) super(normalize_time(time)) end
Sets ‘time` as the `modified_time` attribute value.
@param [String, Integer, Time, nil] time The modified time.
If `time` is `Integer`, it is used as UNIX time.
Source
# File lib/chupa-text/attributes.rb, line 31 def to_h super.merge(@extra_data) end
Private Instance Methods
Source
# File lib/chupa-text/attributes.rb, line 107 def normalize_encoding(encoding) if encoding.is_a?(String) encoding = Encoding.find(encoding) end encoding end
Source
# File lib/chupa-text/attributes.rb, line 103 def normalize_name(name) name.to_sym end
Source
# File lib/chupa-text/attributes.rb, line 114 def normalize_time(time) case time when String Time.parse(time) when Integer Time.at(time).utc else time end end