Class: Inkan
Instance Attribute Summary (collapse)
-
- (Object) comment
Returns the value of attribute comment.
-
- (Object) comment_suffix
Returns the value of attribute comment_suffix.
-
- (Object) credit
Returns the value of attribute credit.
Class Method Summary (collapse)
Instance Method Summary (collapse)
-
- (Inkan) initialize(file)
constructor
A new instance of Inkan.
- - (Object) print(string)
- - (Object) puts(string)
- - (Object) render
- - (Object) seal
Constructor Details
- (Inkan) initialize(file)
A new instance of Inkan
31 32 33 34 35 36 37 38 |
# File 'lib/inkan/inkan.rb', line 31 def initialize(file) @file = file # Set Defaults @credit = 'Generated by Inkan' @comment = '#' @comment_suffix = '' end |
Instance Attribute Details
- (Object) comment
Returns the value of attribute comment
2 3 4 |
# File 'lib/inkan/inkan.rb', line 2 def comment @comment end |
- (Object) comment_suffix
Returns the value of attribute comment_suffix
2 3 4 |
# File 'lib/inkan/inkan.rb', line 2 def comment_suffix @comment_suffix end |
- (Object) credit
Returns the value of attribute credit
2 3 4 |
# File 'lib/inkan/inkan.rb', line 2 def credit @credit end |
Class Method Details
+ (Boolean) legitimate?(filename)
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/inkan/inkan.rb', line 4 def self.legitimate?(filename) File.open(filename) do |file| file_content = file.read seal, content = if file_content[/\A#!/] hashbang, seal, remaining_content = file_content.split("\n", 3) [seal, "#{hashbang}\n#{remaining_content}"] else file_content.split("\n", 2) end !seal[/\s#{sha(content || '')}\s*$/].nil? end end |
+ (Object) render
22 23 24 |
# File 'lib/inkan/inkan.rb', line 22 def self.render new(nil).tap {|inkan| yield inkan }.render end |
+ (Object) seal(file)
18 19 20 |
# File 'lib/inkan/inkan.rb', line 18 def self.seal(file) new(file).tap {|inkan| yield inkan }.seal end |
+ (Object) sha(content)
26 27 28 29 |
# File 'lib/inkan/inkan.rb', line 26 def self.sha(content) require 'digest/sha1' Digest::SHA1.hexdigest(content) end |
Instance Method Details
- (Object) print(string)
40 41 42 |
# File 'lib/inkan/inkan.rb', line 40 def print(string) file_content << string end |
- (Object) puts(string)
44 45 46 |
# File 'lib/inkan/inkan.rb', line 44 def puts(string) file_content << string << "\n" end |
- (Object) render
54 55 56 57 58 59 60 61 |
# File 'lib/inkan/inkan.rb', line 54 def render if file_content[/\A#!/] hashbang, remaining_content = file_content.split("\n", 2) "#{hashbang}\n#{render_seal}\n#{remaining_content}" else "#{render_seal}\n#{file_content}" end end |
- (Object) seal
48 49 50 51 52 |
# File 'lib/inkan/inkan.rb', line 48 def seal File.open(@file, 'w') do |f| f.print render end end |