Class: Transcriptic::Labfile

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/transcriptic/labfile.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Labfile

Returns a new instance of Labfile.



17
18
19
20
21
# File 'lib/transcriptic/labfile.rb', line 17

def initialize(path)
  @filepath         = path
  @options          = Hash.new
  @dependencies     = []
end

Class Method Details

.from_file(file) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/transcriptic/labfile.rb', line 8

def from_file(file)
  content = File.read(file)
  object = new(file)
  object.load(content)
rescue Errno::ENOENT => e
  raise FileNotFound, "No Labfile found at: #{file}"
end

Instance Method Details

#author(name) ⇒ Object



45
46
47
# File 'lib/transcriptic/labfile.rb', line 45

def author(name)
  @options[:author] = name
end

#dependenciesObject



69
70
71
# File 'lib/transcriptic/labfile.rb', line 69

def dependencies
  @dependencies
end

#dependency(group, name, version) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/transcriptic/labfile.rb', line 61

def dependency(group, name, version)
  @dependencies << {
    group: group,
    name: name,
    version: version
  }
end

#description(desc) ⇒ Object



57
58
59
# File 'lib/transcriptic/labfile.rb', line 57

def description(desc)
  @options[:description] = desc
end

#email(email) ⇒ Object



49
50
51
# File 'lib/transcriptic/labfile.rb', line 49

def email(email)
  @options[:email] = email
end

#load(content) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/transcriptic/labfile.rb', line 23

def load(content)
  begin
    instance_eval(content)
  rescue => e
    puts e
    raise LabfileReadError.new(e)
  end
  self
end

#name(name = nil) ⇒ Object



41
42
43
# File 'lib/transcriptic/labfile.rb', line 41

def name(name = nil)
  @options[:name] = name
end

#optionsObject



37
38
39
# File 'lib/transcriptic/labfile.rb', line 37

def options
  @options
end

#shaObject



33
34
35
# File 'lib/transcriptic/labfile.rb', line 33

def sha
  @sha ||= Digest::SHA1.hexdigest File.read(filepath.to_s)
end

#version(arg) ⇒ Object



53
54
55
# File 'lib/transcriptic/labfile.rb', line 53

def version(arg)
  @options[:version] = arg
end