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

Returns a new instance of Attributes.



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

Returns:

  • (Object)

    the current value of 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

Returns:

  • (Object)

    the current value of 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

Returns:

  • (Object)

    the current value of 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

Returns:

  • (Object)

    the current value of 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

Returns:

  • (Object)

    the current value of 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.

Parameters:

  • name (Symbol, String)

    The attribute name.

Returns:

  • (Object)

    The attribute value.



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.

Parameters:

  • name (Symbol, String)

    The attribute name.

  • value (Object)

    The attribute value.



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