Class: Aio::Text::Block

Inherits:
Object
  • Object
show all
Defined in:
lib/aio/core/text/block.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block) ⇒ Block

Returns a new instance of Block.



5
6
7
# File 'lib/aio/core/text/block.rb', line 5

def initialize(block)
  @block = block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args) ⇒ Object



78
79
80
81
82
83
84
85
# File 'lib/aio/core/text/block.rb', line 78

def method_missing(m, *args)
  if @block.respond_to? m
    @block.send(m, args)

  else
    super
  end
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



3
4
5
# File 'lib/aio/core/text/block.rb', line 3

def content
  @content
end

#lineObject

Returns the value of attribute line.



3
4
5
# File 'lib/aio/core/text/block.rb', line 3

def line
  @line
end

Instance Method Details

#[](sym) ⇒ Object



17
18
19
# File 'lib/aio/core/text/block.rb', line 17

def [](sym)
  @block[sym]
end

#inspectObject



9
10
11
# File 'lib/aio/core/text/block.rb', line 9

def inspect
  @block.inspect
end

#match_string(str) ⇒ Object

加入content和行数信息



74
75
76
# File 'lib/aio/core/text/block.rb', line 74

def match_string(str)
  MatchStringInfo.new(str, content, line)
end

#nil?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/aio/core/text/block.rb', line 13

def nil?
  @block.nil?
end

#update(info, sym, str = nil) ⇒ Object

有两种更新的方式,不加str 那么就是从block中的提取如果有str, 则直接使用str



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/aio/core/text/block.rb', line 23

def update(info, sym, str=nil)
  sym = sym.to_sym
  if info.nil?
    print_error "请检查update中的第一个参数是否定义" 
    pp caller
  end

  if str.nil?
    info[sym] = match_string(self[sym].strip)
  else
    info[sym] = match_string(str.to_s.strip)
  end
end

#update_arr(info, sym) ⇒ Object



37
38
39
40
41
# File 'lib/aio/core/text/block.rb', line 37

def update_arr(info, sym)
  sym = sym.to_sym
  info[sym] ||= []
  info[sym] << match_string(self[sym].strip)
end

#update_hash(info, sym, key, val) ⇒ Object



43
44
45
46
47
# File 'lib/aio/core/text/block.rb', line 43

def update_hash(info, sym, key, val)
  sym = sym.to_sym
  info[sym] ||= {}
  info[sym][key] = match_string(val.strip)
end

#warning(info, sym, level, mod, opt = {}) ⇒ Object

参数info 放置useful 参数sym 为Symbol类型的标示参数level 为 :serious 或 :ordinary 参数mod 一般为self 参数opt 当block中没有sym项时使用



54
55
56
57
58
59
# File 'lib/aio/core/text/block.rb', line 54

def warning(info, sym, level, mod, opt={})
  sym = sym.to_sym
  self.update(info, sym, opt[:string])
  # Aio::Text::Warning 类中的warning方法
  mod.warning_klass.warning(info, sym, level, mod, opt[:force])
end

#warning_ordinary(info, sym, mod, opt = {}) ⇒ Object



67
68
69
70
71
# File 'lib/aio/core/text/block.rb', line 67

def warning_ordinary(info, sym, mod, opt={})
  sym = sym.to_sym
  self.update(info, sym, opt[:string])
  mod.warning_klass.warning_ordinary(info, sym, mod, opt[:force])
end

#warning_serious(info, sym, mod, opt = {}) ⇒ Object



61
62
63
64
65
# File 'lib/aio/core/text/block.rb', line 61

def warning_serious(info, sym, mod, opt={})
  sym = sym.to_sym
  self.update(info, sym, opt[:string])
  mod.warning_klass.warning_serious(info, sym, mod, opt[:force])
end