Class: Kang::Data
- Inherits:
-
Object
- Object
- Kang::Data
- Defined in:
- lib/kang.rb
Instance Method Summary collapse
-
#initialize(reg_text = "", match_text = "") ⇒ Data
constructor
A new instance of Data.
- #match? ⇒ Boolean
- #match_begin ⇒ Object
- #match_end ⇒ Object
- #match_group_count ⇒ Object
- #matches ⇒ Object
- #regexp_valid? ⇒ Boolean
- #update_match ⇒ Object
- #update_match_string(match_string) ⇒ Object
- #update_regexp(re_string) ⇒ Object
Constructor Details
#initialize(reg_text = "", match_text = "") ⇒ Data
Returns a new instance of Data.
28 29 30 31 |
# File 'lib/kang.rb', line 28 def initialize(reg_text="",match_text="") update_regexp(reg_text) update_match_string(match_text) end |
Instance Method Details
#match? ⇒ Boolean
67 68 69 |
# File 'lib/kang.rb', line 67 def match? @match ? true : false end |
#match_begin ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/kang.rb', line 71 def match_begin if @match @match.begin(0) else nil end end |
#match_end ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/kang.rb', line 79 def match_end if @match @match.end(0) else nil end end |
#match_group_count ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/kang.rb', line 46 def match_group_count if @match @match.length else nil end end |
#matches ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/kang.rb', line 87 def matches if @match and (@match.length > 1) @match.to_a else [] end end |
#regexp_valid? ⇒ Boolean
63 64 65 |
# File 'lib/kang.rb', line 63 def regexp_valid? @re.nil? ? false : true end |
#update_match ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/kang.rb', line 38 def update_match if @re @match = @re.match(@match_string) else @match = nil end end |
#update_match_string(match_string) ⇒ Object
33 34 35 36 |
# File 'lib/kang.rb', line 33 def update_match_string(match_string) @match_string = match_string update_match end |
#update_regexp(re_string) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/kang.rb', line 54 def update_regexp(re_string) begin @re = Regexp.new(re_string) rescue RegexpError @re = nil end update_match end |