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)


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

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.



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

def bookformat
  @bookformat
end

#cv_separatorObject

Returns the value of attribute cv_separator.



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

def cv_separator
  @cv_separator
end

#hyphen_separatorObject

Returns the value of attribute hyphen_separator.



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

def hyphen_separator
  @hyphen_separator
end

#pass_separatorObject

Returns the value of attribute pass_separator.



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

def pass_separator
  @pass_separator
end

Instance Method Details

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

Formats a reference (array of passages and maybe separators)



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

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



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

def format_addon a
  a.to_s
end

#format_book(osis_book_id) ⇒ Object

Formats a book

Parameters:

  • osis_book_id

    OSIS-ID for book



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

def format_book osis_book_id
  osis_book_id_to_book_name[osis_book_id].send @bookformat
end

#format_chapter(num) ⇒ Object

Formats a chapter

Parameters:

  • num

    number of chapter



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

def format_chapter num
  num.to_s
end

#format_postfix(p) ⇒ Object

Formats a verse postfix



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

def format_postfix p
  p.to_s
end

#format_verse(num) ⇒ Object

Formats a verse

Parameters:

  • num

    number of verse



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

def format_verse num
  num.to_s
end