Class: Kang::Data
- Inherits:
-
Object
- Object
- Kang::Data
- Defined in:
- lib/kang/data.rb
Instance Attribute Summary collapse
-
#line_number ⇒ Object
Returns the value of attribute line_number.
-
#match_string ⇒ Object
Returns the value of attribute match_string.
-
#regex_string ⇒ Object
Returns the value of attribute regex_string.
Instance Method Summary collapse
-
#initialize(reg_text = "", match_text = "") ⇒ Data
constructor
A new instance of Data.
- #line(line_num) ⇒ Object
- #match ⇒ Object
- #match? ⇒ Boolean
- #match_begin(group = 0) ⇒ Object
- #match_end(group = 0) ⇒ Object
- #match_group_count ⇒ Object
- #matches ⇒ Object
- #multiline ⇒ Object
- #multiline=(multiline) ⇒ Object
- #num_lines ⇒ Object
- #regex_valid? ⇒ Boolean
Constructor Details
#initialize(reg_text = "", match_text = "") ⇒ Data
Returns a new instance of Data.
21 22 23 24 25 26 27 |
# File 'lib/kang/data.rb', line 21 def initialize(reg_text="",match_text="") self.match_string = match_text self.regex_string = reg_text @line_number=1 @multiline=false update_match end |
Instance Attribute Details
#line_number ⇒ Object
Returns the value of attribute line_number.
19 20 21 |
# File 'lib/kang/data.rb', line 19 def line_number @line_number end |
#match_string ⇒ Object
Returns the value of attribute match_string.
19 20 21 |
# File 'lib/kang/data.rb', line 19 def match_string @match_string end |
#regex_string ⇒ Object
Returns the value of attribute regex_string.
19 20 21 |
# File 'lib/kang/data.rb', line 19 def regex_string @regex_string end |
Instance Method Details
#line(line_num) ⇒ Object
77 78 79 |
# File 'lib/kang/data.rb', line 77 def line(line_num) @line_matches[line_num][0] end |
#match ⇒ Object
57 58 59 |
# File 'lib/kang/data.rb', line 57 def match @match end |
#match? ⇒ Boolean
85 86 87 |
# File 'lib/kang/data.rb', line 85 def match? @match ? true : false end |
#match_begin(group = 0) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/kang/data.rb', line 89 def match_begin(group=0) if @match @match.begin(group) else nil end end |
#match_end(group = 0) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/kang/data.rb', line 97 def match_end(group=0) if @match @match.end(group) else nil end end |
#match_group_count ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/kang/data.rb', line 105 def match_group_count if @match @match.length else nil end end |
#matches ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/kang/data.rb', line 113 def matches if @match and (@match.length > 1) if @match.names and @match.names.size>0 names = @match.names.unshift("0") else names = Range.new(0,@match.length-1).to_a.collect{|o| o.to_s} end return names.zip(@match.to_a) else [] end end |
#multiline ⇒ Object
53 54 55 |
# File 'lib/kang/data.rb', line 53 def multiline @multiline end |
#multiline=(multiline) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/kang/data.rb', line 44 def multiline=(multiline) if multiline @multiline = true else @multiline = false end update_match end |
#num_lines ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/kang/data.rb', line 68 def num_lines #if (defined? @line_matches) and @multiline #@line_matches.size - 1 #line_match is padded with a leading nil to deal with 0 offset #else #nil #end @match_string.scan(/^.*$/).size end |
#regex_valid? ⇒ Boolean
81 82 83 |
# File 'lib/kang/data.rb', line 81 def regex_valid? @re.nil? ? false : true end |