Class: Chirp::Context
- Inherits:
-
Object
- Object
- Chirp::Context
- Includes:
- FileUtils
- Defined in:
- lib/chirp/context.rb
Instance Attribute Summary collapse
- #contents ⇒ Object
-
#dir ⇒ Object
Returns the value of attribute dir.
-
#field_separator ⇒ Object
Returns the value of attribute field_separator.
- #fields ⇒ Object
-
#line ⇒ Object
Returns the value of attribute line.
-
#line_no ⇒ Object
Returns the value of attribute line_no.
-
#output_path ⇒ Object
Returns the value of attribute output_path.
-
#path ⇒ Object
Returns the value of attribute path.
-
#paths ⇒ Object
Returns the value of attribute paths.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
- #basename ⇒ Object
- #comment(*msg) ⇒ Object
- #debug(*msg) ⇒ Object
- #dirname ⇒ Object
- #execute(action) ⇒ Object
- #extname ⇒ Object
- #full_path ⇒ Object
- #full_path_name ⇒ Object
-
#initialize ⇒ Context
constructor
A new instance of Context.
- #name ⇒ Object
- #path_name ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Context
Returns a new instance of Context.
20 21 22 23 24 |
# File 'lib/chirp/context.rb', line 20 def initialize @field_separator = /[ \t]/ @verbose = false @dir = '.' end |
Instance Attribute Details
#contents ⇒ Object
85 86 87 |
# File 'lib/chirp/context.rb', line 85 def contents @contents || @contents = File.read(full_path) end |
#dir ⇒ Object
Returns the value of attribute dir.
15 16 17 |
# File 'lib/chirp/context.rb', line 15 def dir @dir end |
#field_separator ⇒ Object
Returns the value of attribute field_separator.
15 16 17 |
# File 'lib/chirp/context.rb', line 15 def field_separator @field_separator end |
#fields ⇒ Object
56 57 58 |
# File 'lib/chirp/context.rb', line 56 def fields @fields || @fields = line.split(@field_separator) end |
#line ⇒ Object
Returns the value of attribute line.
16 17 18 |
# File 'lib/chirp/context.rb', line 16 def line @line end |
#line_no ⇒ Object
Returns the value of attribute line_no.
15 16 17 |
# File 'lib/chirp/context.rb', line 15 def line_no @line_no end |
#output_path ⇒ Object
Returns the value of attribute output_path.
15 16 17 |
# File 'lib/chirp/context.rb', line 15 def output_path @output_path end |
#path ⇒ Object
Returns the value of attribute path.
16 17 18 |
# File 'lib/chirp/context.rb', line 16 def path @path end |
#paths ⇒ Object
Returns the value of attribute paths.
15 16 17 |
# File 'lib/chirp/context.rb', line 15 def paths @paths end |
#verbose ⇒ Object
Returns the value of attribute verbose.
18 19 20 |
# File 'lib/chirp/context.rb', line 18 def verbose @verbose end |
Instance Method Details
#basename ⇒ Object
72 73 74 |
# File 'lib/chirp/context.rb', line 72 def basename @basename || @basename = path_name.basename.to_s end |
#comment(*msg) ⇒ Object
89 90 91 |
# File 'lib/chirp/context.rb', line 89 def comment(*msg) STDERR.puts(msg.join(' ')) end |
#debug(*msg) ⇒ Object
93 94 95 |
# File 'lib/chirp/context.rb', line 93 def debug(*msg) STDERR.puts(msg.join(' ')) if @verbose end |
#dirname ⇒ Object
68 69 70 |
# File 'lib/chirp/context.rb', line 68 def dirname @dirname || @dirname = path_name.dirname.to_s end |
#execute(action) ⇒ Object
26 27 28 |
# File 'lib/chirp/context.rb', line 26 def execute(action) instance_eval(&action) end |
#extname ⇒ Object
76 77 78 |
# File 'lib/chirp/context.rb', line 76 def extname @extname || @extname = path_name.extname.to_s end |
#full_path ⇒ Object
52 53 54 |
# File 'lib/chirp/context.rb', line 52 def full_path @full_path || @full_path = File.join(dir, path) end |
#full_path_name ⇒ Object
64 65 66 |
# File 'lib/chirp/context.rb', line 64 def full_path_name @full_path_name || @full_path_name = Pathname.new(File.join(dir,path)) end |
#name ⇒ Object
80 81 82 83 |
# File 'lib/chirp/context.rb', line 80 def name return @name if @name @name = basename[0..-extname.size-1] end |
#path_name ⇒ Object
60 61 62 |
# File 'lib/chirp/context.rb', line 60 def path_name @path_name || @path_name = Pathname.new(path) end |
#to_s ⇒ Object
97 98 99 |
# File 'lib/chirp/context.rb', line 97 def to_s return "Context: #{@path}" end |