Class: Glark::Context
- Inherits:
-
Object
- Object
- Glark::Context
- Includes:
- Logue::Loggable
- 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.
11 12 13 |
# File 'lib/glark/output/context.rb', line 11 def initialize clear end |
Instance Attribute Details
#after ⇒ Object
Returns the value of attribute after.
8 9 10 |
# File 'lib/glark/output/context.rb', line 8 def after @after end |
#before ⇒ Object
Returns the value of attribute before.
9 10 11 |
# File 'lib/glark/output/context.rb', line 9 def before @before end |
Instance Method Details
#add_as_option(optdata) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/glark/output/context.rb', line 33 def add_as_option optdata optdata << { :tags => %w{ -C --context }, :regexp => %r{ ^ - ([1-9]\d*) $ }x, :arg => [ :optional, :integer ], :process => Proc.new { |val, opt, args| @after = @before = val == true ? 2 : val }, :rcname => %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
15 16 17 18 |
# File 'lib/glark/output/context.rb', line 15 def clear @after = 0 @before = 0 end |
#update_fields(fields) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/glark/output/context.rb', line 20 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 |