Class: SixArm::Markdown::Headline
- Inherits:
-
Object
- Object
- SixArm::Markdown::Headline
- Includes:
- EqualInstanceVariables
- Defined in:
- lib/sixarm_ruby_markdown/sixarm/markdown/headline.rb
Instance Attribute Summary collapse
-
#anchor ⇒ Object
Returns the value of attribute anchor.
-
#level ⇒ Object
Returns the value of attribute level.
-
#link ⇒ Object
Returns the value of attribute link.
-
#text ⇒ Object
Returns the value of attribute text.
Class Method Summary collapse
- .parse_line(line) ⇒ Object
- .parse_line_level(line) ⇒ Object
- .text_to_anchor(text) ⇒ Object
- .trim_line(line) ⇒ Object
Instance Method Summary collapse
-
#initialize(text: nil, anchor: nil, level: nil, link: nil) ⇒ Headline
constructor
A new instance of Headline.
Constructor Details
#initialize(text: nil, anchor: nil, level: nil, link: nil) ⇒ Headline
Returns a new instance of Headline.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/sixarm_ruby_markdown/sixarm/markdown/headline.rb', line 16 def initialize( text: nil, anchor: nil, level: nil, link: nil ) raise ArgumentError if !text.kind_of?(String) @text = text @anchor = anchor || self.class.text_to_anchor(text) @level = level @link = link end |
Instance Attribute Details
#anchor ⇒ Object
Returns the value of attribute anchor.
10 11 12 |
# File 'lib/sixarm_ruby_markdown/sixarm/markdown/headline.rb', line 10 def anchor @anchor end |
#level ⇒ Object
Returns the value of attribute level.
10 11 12 |
# File 'lib/sixarm_ruby_markdown/sixarm/markdown/headline.rb', line 10 def level @level end |
#link ⇒ Object
Returns the value of attribute link.
10 11 12 |
# File 'lib/sixarm_ruby_markdown/sixarm/markdown/headline.rb', line 10 def link @link end |
#text ⇒ Object
Returns the value of attribute text.
10 11 12 |
# File 'lib/sixarm_ruby_markdown/sixarm/markdown/headline.rb', line 10 def text @text end |
Class Method Details
.parse_line(line) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/sixarm_ruby_markdown/sixarm/markdown/headline.rb', line 41 def self.parse_line(line) level = parse_line_level(line) text = trim_line(line) # TODO Add parser for anchor # TODO Add parser for Unicode normalization return SixArm::Markdown::Headline.new(text: text, level: level) end |
.parse_line_level(line) ⇒ Object
49 50 51 |
# File 'lib/sixarm_ruby_markdown/sixarm/markdown/headline.rb', line 49 def self.parse_line_level(line) return line =~/^\s*([#=]+)/ ? $1.length : nil end |
.text_to_anchor(text) ⇒ Object
57 58 59 |
# File 'lib/sixarm_ruby_markdown/sixarm/markdown/headline.rb', line 57 def self.text_to_anchor(text) text.downcase.gsub(/\W+/,'-') end |
.trim_line(line) ⇒ Object
53 54 55 |
# File 'lib/sixarm_ruby_markdown/sixarm/markdown/headline.rb', line 53 def self.trim_line(line) line.sub(/^\s*[#=]+\s+/, '').sub(/\s+[#=]+\s*$/, '') end |