Class: Faun::Section

Inherits:
Object
  • Object
show all
Defined in:
lib/faun.rb

Direct Known Subclasses

ForumThread, Post, SectionWithMeta

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, name, path, type) ⇒ Section

Returns a new instance of Section.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/faun.rb', line 15

def initialize(id, name, path, type)
  @id = id
  @name = name

  subs = {}
  Dir.each_child(path) do |section|
    dir = File.join(path, section)
    next unless File.directory?(dir) and not section.start_with?('.')

    name, _, id = section.rpartition(".@")
    id = id.to_i
    subs[id] = type.new(id, name, dir)
  end
  @items = subs.sort_by { |subid, _| subid }.to_h
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



13
14
15
# File 'lib/faun.rb', line 13

def id
  @id
end

#itemsObject (readonly)

Returns the value of attribute items.



13
14
15
# File 'lib/faun.rb', line 13

def items
  @items
end

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/faun.rb', line 13

def name
  @name
end

Instance Method Details

#each(&block) ⇒ Object



31
32
33
# File 'lib/faun.rb', line 31

def each(&block)
  @items.each(&block)
end

#each_key(&block) ⇒ Object



35
36
37
# File 'lib/faun.rb', line 35

def each_key(&block)
  @items.each_key(&block)
end

#each_value(&block) ⇒ Object



39
40
41
# File 'lib/faun.rb', line 39

def each_value(&block)
  @items.each_value(&block)
end

#to_json(*args) ⇒ Object



43
44
45
46
47
48
# File 'lib/faun.rb', line 43

def to_json(*args)
  {
    :id => @id,
    item_name => @items
  }.to_json(*args)
end