Class: Stretto::Tokens::DurationToken

Inherits:
Treetop::Runtime::SyntaxNode
  • Object
show all
Defined in:
lib/stretto/grammar/tokens/duration_token.rb

Overview

Token result from parsing a duration

Examples:

“wh”, “q*3:4”, “/2.5”

Instance Method Summary collapse

Instance Method Details

#dotsString

Returns a string with the number of dots in the duration

Examples:

2 (for string Cmajh..

Returns:

  • (String)

    Returns a string with the number of dots in the duration



41
42
43
# File 'lib/stretto/grammar/tokens/duration_token.rb', line 41

def dots
  duration_string.dots
end

#duration_characterString

Returns The duration expressed as characters.

Examples:

“h”, “wq”

Returns:

  • (String)

    The duration expressed as characters



30
31
32
# File 'lib/stretto/grammar/tokens/duration_token.rb', line 30

def duration_character
  duration_string.duration_character
end

#end_of_tie?true, false

Returns if the duration ends a tie (e.g., “-w”).

Returns:

  • (true, false)

    if the duration ends a tie (e.g., “-w”)



15
16
17
# File 'lib/stretto/grammar/tokens/duration_token.rb', line 15

def end_of_tie?
  _end_of_tie.text_value.present? if _end_of_tie
end

#start_of_tie?true, false

Returns if the duration starts a tie (e.g., “w-”).

Returns:

  • (true, false)

    if the duration starts a tie (e.g., “w-”)



10
11
12
# File 'lib/stretto/grammar/tokens/duration_token.rb', line 10

def start_of_tie?
  _start_of_tie.text_value.present? if _start_of_tie
end

#tupletHash?

Returns A hash containing both the numerator and denominator, if present.

Examples:

{ :numerator => 2, :denominator => 3 }

Returns:

  • (Hash, nil)

    A hash containing both the numerator and denominator, if present



21
22
23
24
25
26
# File 'lib/stretto/grammar/tokens/duration_token.rb', line 21

def tuplet
  if duration_string.tuplet
    {:numerator   => duration_string.tuplet.numerator,
     :denominator => duration_string.tuplet.denominator}
  end
end

#valueValue?

Returns A value wrapping the value of the duration, if present.

Returns:

  • (Value, nil)

    A value wrapping the value of the duration, if present



35
36
37
# File 'lib/stretto/grammar/tokens/duration_token.rb', line 35

def value
  Stretto::Value.new(duration_string.value.wrap) if duration_string.value
end