Class: Emmett::Section

Inherits:
Struct
  • Object
show all
Defined in:
lib/emmett/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



14
15
16
# File 'lib/emmett/document.rb', line 14

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object



28
29
30
# File 'lib/emmett/document.rb', line 28

def ==(other)
  other.is_a?(self.class) && other.name == name
end

#groupsObject



16
17
18
# File 'lib/emmett/document.rb', line 16

def groups
  @groups ||= []
end

#groups=(value) ⇒ Object



20
21
22
# File 'lib/emmett/document.rb', line 20

def groups=(value)
  @groups = Array value
end

#singular?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/emmett/document.rb', line 24

def singular?
  @groups.one?
end

#to_hashObject



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/emmett/document.rb', line 32

def to_hash
  {
    :name     => name,
    :singular => singular?,
    :groups   => groups.map(&:to_hash)
  }.tap do |result|
    if singular?
      group = groups.first.to_hash
      result[:endpoints] = group[:endpoints]
      result[:url]       = group[:url]
    end
  end
end