Class: Glark::Context
- Inherits:
-
Object
- Object
- Glark::Context
- Defined in:
- lib/glark/output/context.rb
Instance Attribute Summary collapse
-
#after ⇒ Object
Returns the value of attribute after.
-
#before ⇒ Object
Returns the value of attribute before.
Instance Method Summary collapse
- #add_as_option(optdata) ⇒ Object
- #clear ⇒ Object
-
#initialize ⇒ Context
constructor
A new instance of Context.
- #update_fields(fields) ⇒ Object
Constructor Details
#initialize ⇒ Context
Returns a new instance of Context.
9 10 11 12 |
# File 'lib/glark/output/context.rb', line 9 def initialize @after = 0 @before = 0 end |
Instance Attribute Details
#after ⇒ Object
Returns the value of attribute after.
6 7 8 |
# File 'lib/glark/output/context.rb', line 6 def after @after end |
#before ⇒ Object
Returns the value of attribute before.
7 8 9 |
# File 'lib/glark/output/context.rb', line 7 def before @before end |
Instance Method Details
#add_as_option(optdata) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/glark/output/context.rb', line 32 def add_as_option optdata optdata << { :tags => %w{ -C --context }, :res => %r{ ^ - ([1-9]\d*) $ }x, :arg => [ :optional, :integer ], :set => Proc.new { |val, opt, args| @after = @before = val || 2 }, :rc => %w{ context }, } optdata << { :tags => %w{ --after-context -A }, :arg => [ :integer ], :set => Proc.new { |val| @after = val }, :rc => %w{ after-context }, } optdata << { :tags => %w{ --before-context -B }, :arg => [ :integer ], :set => Proc.new { |val| @before = val }, :rc => %w{ before-context }, } end |
#clear ⇒ Object
14 15 16 17 |
# File 'lib/glark/output/context.rb', line 14 def clear @after = 0 @before = 0 end |
#update_fields(fields) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/glark/output/context.rb', line 19 def update_fields fields fields.each do |name, values| case name when 'context' @after = @before = values.last.to_i when 'after', 'after-context' @after = values.last.to_i when 'before', 'before-context' @before = values.last.to_i end end end |