Class: Chirp::Context

Inherits:
Object
  • Object
show all
Includes:
FileUtils
Defined in:
lib/chirp/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeContext

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

#contentsObject



85
86
87
# File 'lib/chirp/context.rb', line 85

def contents
  @contents || @contents = File.read(full_path)
end

#dirObject

Returns the value of attribute dir.



15
16
17
# File 'lib/chirp/context.rb', line 15

def dir
  @dir
end

#field_separatorObject

Returns the value of attribute field_separator.



15
16
17
# File 'lib/chirp/context.rb', line 15

def field_separator
  @field_separator
end

#fieldsObject



56
57
58
# File 'lib/chirp/context.rb', line 56

def fields
  @fields || @fields = line.split(@field_separator)
end

#lineObject

Returns the value of attribute line.



16
17
18
# File 'lib/chirp/context.rb', line 16

def line
  @line
end

#line_noObject

Returns the value of attribute line_no.



15
16
17
# File 'lib/chirp/context.rb', line 15

def line_no
  @line_no
end

#output_pathObject

Returns the value of attribute output_path.



15
16
17
# File 'lib/chirp/context.rb', line 15

def output_path
  @output_path
end

#pathObject

Returns the value of attribute path.



16
17
18
# File 'lib/chirp/context.rb', line 16

def path
  @path
end

#pathsObject

Returns the value of attribute paths.



15
16
17
# File 'lib/chirp/context.rb', line 15

def paths
  @paths
end

#verboseObject

Returns the value of attribute verbose.



18
19
20
# File 'lib/chirp/context.rb', line 18

def verbose
  @verbose
end

Instance Method Details

#basenameObject



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

#dirnameObject



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

#extnameObject



76
77
78
# File 'lib/chirp/context.rb', line 76

def extname
  @extname || @extname = path_name.extname.to_s
end

#full_pathObject



52
53
54
# File 'lib/chirp/context.rb', line 52

def full_path
  @full_path || @full_path = File.join(dir, path)
end

#full_path_nameObject



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

#nameObject



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_nameObject



60
61
62
# File 'lib/chirp/context.rb', line 60

def path_name
  @path_name || @path_name = Pathname.new(path)
end

#to_sObject



97
98
99
# File 'lib/chirp/context.rb', line 97

def to_s
  return "Context: #{@path}"
end