Class: Rapid::Template::Pulling::Explicit
- Defined in:
- lib/rapid/template/pulling/explicit.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#previous_content ⇒ Object
readonly
Returns the value of attribute previous_content.
Attributes inherited from Base
Instance Method Summary collapse
- #empty! ⇒ Object
- #index(content) ⇒ Object
-
#initialize(content) ⇒ Explicit
constructor
A new instance of Explicit.
- #match(content) ⇒ Object
- #match!(content) ⇒ Object
- #move!(count) ⇒ Object
- #raise_not_matching(content) ⇒ Object
- #starts_with(content) ⇒ Object
- #starts_with?(content) ⇒ Boolean
Methods inherited from Base
Constructor Details
#initialize(content) ⇒ Explicit
Returns a new instance of Explicit.
9 10 11 12 13 |
# File 'lib/rapid/template/pulling/explicit.rb', line 9 def initialize content super @content = content.clone @previous_content = "" end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
7 8 9 |
# File 'lib/rapid/template/pulling/explicit.rb', line 7 def content @content end |
#previous_content ⇒ Object (readonly)
Returns the value of attribute previous_content.
7 8 9 |
# File 'lib/rapid/template/pulling/explicit.rb', line 7 def previous_content @previous_content end |
Instance Method Details
#empty! ⇒ Object
49 50 51 52 53 |
# File 'lib/rapid/template/pulling/explicit.rb', line 49 def empty! unless @content.nil? || @content.empty? raise_not_matching "" end end |
#index(content) ⇒ Object
15 16 17 |
# File 'lib/rapid/template/pulling/explicit.rb', line 15 def index content @content.index content end |
#match(content) ⇒ Object
36 37 38 |
# File 'lib/rapid/template/pulling/explicit.rb', line 36 def match content internal_match @content, content end |
#match!(content) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/rapid/template/pulling/explicit.rb', line 40 def match! content result, a, b = match content unless result raise_not_matching content end move! a end |
#move!(count) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/rapid/template/pulling/explicit.rb', line 27 def move! count return 0 if count == 0 matched = @content.slice!(0..count-1) @previous_content << matched @previous_content = @previous_content[@previous_content.length - 50..-1] if @previous_content.length > 50 count end |
#raise_not_matching(content) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rapid/template/pulling/explicit.rb', line 55 def raise_not_matching content failure, a_count, b_count = internal_match_miss @content, content if a_count > 0 move! a_count end if b_count > 0 content = content[b_count..-1] end raise Rapid::NotMatchingTemplateError.new(result, content, @content, :previous => @previous_content) end |
#starts_with(content) ⇒ Object
23 24 25 |
# File 'lib/rapid/template/pulling/explicit.rb', line 23 def starts_with content content.length if @content.starts_with? content end |
#starts_with?(content) ⇒ Boolean
19 20 21 |
# File 'lib/rapid/template/pulling/explicit.rb', line 19 def starts_with? content @content.starts_with? content end |