Class: ChupaText::Attributes

Inherits:
Struct
  • Object
show all
Includes:
Enumerable
Defined in:
lib/chupa-text/attributes.rb

Overview

Attributes of data.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAttributes



26
27
28
29
# File 'lib/chupa-text/attributes.rb', line 26

def initialize
  super
  @extra_data = {}
end

Instance Attribute Details

#authorObject

Returns the value of attribute author



19
20
21
# File 'lib/chupa-text/attributes.rb', line 19

def author
  @author
end

#created_timeObject

Returns the value of attribute created_time



19
20
21
# File 'lib/chupa-text/attributes.rb', line 19

def created_time
  @created_time
end

#encodingObject

Returns the value of attribute encoding



19
20
21
# File 'lib/chupa-text/attributes.rb', line 19

def encoding
  @encoding
end

#modified_timeObject

Returns the value of attribute modified_time



19
20
21
# File 'lib/chupa-text/attributes.rb', line 19

def modified_time
  @modified_time
end

#titleObject

Returns the value of attribute title



19
20
21
# File 'lib/chupa-text/attributes.rb', line 19

def title
  @title
end

Instance Method Details

#[](name) ⇒ Object

Gets the value of attribute named name.



57
58
59
60
61
62
63
64
# 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

#[]=(name, value) ⇒ Object

Sets value as the value of attribute named name.



70
71
72
73
74
75
76
77
# 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

#each {|name, value| ... } ⇒ Object

Yields:

  • (name, value)

    Gives attribute name and value to the block.

Yield Parameters:

  • name (Symbol)

    The attribute name.

  • value (Object)

    The attribute value.



44
45
46
47
48
49
50
51
# 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

#inspectObject



35
36
37
38
39
# File 'lib/chupa-text/attributes.rb', line 35

def inspect
  super.gsub(/>\z/) do
    " @extra_data=#{@extra_data.inspect}>"
  end
end

#to_hObject



31
32
33
# File 'lib/chupa-text/attributes.rb', line 31

def to_h
  super.merge(@extra_data)
end