Class: Scripref::Formatter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*mods, bookformat: :name) ⇒ Formatter

Returns a new instance of Formatter.

Parameters:

  • mods

    one or more modules to include

  • bookformat (:short use abbreviations, :long use full names of books) (defaults to: :name)


11
12
13
14
15
# File 'lib/scripref/formatter.rb', line 11

def initialize *mods, bookformat: :name
  @mods = mods
  mods.each {|m| extend m}
  @bookformat = bookformat
end

Instance Attribute Details

#bookformatObject

Returns the value of attribute bookformat.



7
8
9
# File 'lib/scripref/formatter.rb', line 7

def bookformat
  @bookformat
end

#cv_separatorObject

Returns the value of attribute cv_separator.



7
8
9
# File 'lib/scripref/formatter.rb', line 7

def cv_separator
  @cv_separator
end

#hyphen_separatorObject

Returns the value of attribute hyphen_separator.



7
8
9
# File 'lib/scripref/formatter.rb', line 7

def hyphen_separator
  @hyphen_separator
end

#pass_separatorObject

Returns the value of attribute pass_separator.



7
8
9
# File 'lib/scripref/formatter.rb', line 7

def pass_separator
  @pass_separator
end

Instance Method Details

#format(*reference) ⇒ Object Also known as: <<

Formats a reference (array of passages and maybe separators)



18
19
20
21
22
23
24
25
26
27
# File 'lib/scripref/formatter.rb', line 18

def format *reference
  @last_b = @last_c = @last_v = :undefined
  @result = []
  reference.flatten.each do |entry|
    next if entry.kind_of? Sep
    @pass = entry
    process_passage
  end
  @result.join
end

#format_addon(a) ⇒ Object

Formats a verse addon



48
49
50
# File 'lib/scripref/formatter.rb', line 48

def format_addon a
  a.to_s
end

#format_book(num) ⇒ Object

Formats a book

Parameters:

  • num

    number of book (starting at 1)



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

def format_book num
  book_names[num - 1].send @bookformat
end

#format_chapter(num) ⇒ Object

Formats a chapter

Parameters:

  • num

    number of chapter



37
38
39
# File 'lib/scripref/formatter.rb', line 37

def format_chapter num
  num.to_s
end

#format_postfix(p) ⇒ Object

Formats a verse postfix



53
54
55
# File 'lib/scripref/formatter.rb', line 53

def format_postfix p
  p.to_s
end

#format_verse(num) ⇒ Object

Formats a verse

Parameters:

  • num

    number of verse



43
44
45
# File 'lib/scripref/formatter.rb', line 43

def format_verse num
  num.to_s
end