Class: Pslm::Psalm

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

Defined Under Namespace

Classes: Strophe, Syllable, Verse, VersePart, Word

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePsalm

Returns a new instance of Psalm.



9
10
11
12
13
# File 'lib/pslm/psalm.rb', line 9

def initialize
  @header = OpenStruct.new
  @header.title = ''
  @strophes = [ Strophe.new ]
end

Instance Attribute Details

#headerObject (readonly)

Returns the value of attribute header.



15
16
17
# File 'lib/pslm/psalm.rb', line 15

def header
  @header
end

#strophesObject (readonly)

Returns the value of attribute strophes.



15
16
17
# File 'lib/pslm/psalm.rb', line 15

def strophes
  @strophes
end

Instance Method Details

#+(ps2) ⇒ Object

returns a new Psalm containing verses of the second appended to the verses of the first; everything else is copied from the first (title etc. of the second Psalm get lost)



41
42
43
44
45
# File 'lib/pslm/psalm.rb', line 41

def +(ps2)
  ps_res = self.dup
  ps_res.strophes.concat ps2.strophes
  return ps_res
end

#==(ps2) ⇒ Object



34
35
36
# File 'lib/pslm/psalm.rb', line 34

def ==(ps2)
  ps2.is_a?(Psalm) && self.header == ps2.header && self.strophes == ps2.strophes
end

#add_strophe(s = nil) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/pslm/psalm.rb', line 22

def add_strophe(s=nil)
  if s != nil then
    @strophes << s
  else
    @strophes << Strophe.new
  end
end

#add_verse(v) ⇒ Object



30
31
32
# File 'lib/pslm/psalm.rb', line 30

def add_verse(v)
  @strophes.last.verses << v
end

#versesObject

accesses all verses of the psalm regardless of the strophes



18
19
20
# File 'lib/pslm/psalm.rb', line 18

def verses
  @strophes.collect {|s| s.verses }.flatten
end