class Header
Handles logic for Header
tokens
Public Class Methods
matches?(text)
click to toggle source
# File lib/rosetta/tokens/header.rb, line 7 def self.matches?(text) return false unless text[0] == '#' text.chars.each do |char| next if char == '#' return char == ' ' end end
new(source_text)
click to toggle source
Calls superclass method
BasicToken::new
# File lib/rosetta/tokens/header.rb, line 17 def initialize(source_text) super(source_text) @depth = determine_depth end
Public Instance Methods
type()
click to toggle source
# File lib/rosetta/tokens/header.rb, line 22 def type "HEADER_#{@depth}".to_sym end
value()
click to toggle source
# File lib/rosetta/tokens/header.rb, line 26 def value @value ||= extract_value_from_text end
Private Instance Methods
determine_depth()
click to toggle source
# File lib/rosetta/tokens/header.rb, line 37 def determine_depth depth = 0 depth += 1 while @source_text[depth] == '#' depth end
extract_value_from_text()
click to toggle source
# File lib/rosetta/tokens/header.rb, line 32 def extract_value_from_text prefix = "#{'#' * @depth} " @source_text.delete_prefix(prefix) end