Class: Kang::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/kang/data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_numberObject

Returns the value of attribute line_number.



19
20
21
# File 'lib/kang/data.rb', line 19

def line_number
  @line_number
end

#match_stringObject

Returns the value of attribute match_string.



19
20
21
# File 'lib/kang/data.rb', line 19

def match_string
  @match_string
end

#regex_stringObject

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

#matchObject



57
58
59
# File 'lib/kang/data.rb', line 57

def match
  @match
end

#match?Boolean

Returns:

  • (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_countObject



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

#matchesObject



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

#multilineObject



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_linesObject



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

Returns:

  • (Boolean)


81
82
83
# File 'lib/kang/data.rb', line 81

def regex_valid?
  @re.nil? ? false : true
end