Class: Licensee::License

Inherits:
Object
  • Object
show all
Defined in:
lib/licensee/license.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ License

Returns a new instance of License.



7
8
9
# File 'lib/licensee/license.rb', line 7

def initialize(name)
  @name=name
end

Instance Attribute Details

#matchObject

Returns the value of attribute match.



5
6
7
# File 'lib/licensee/license.rb', line 5

def match
  @match
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/licensee/license.rb', line 4

def name
  @name
end

Instance Method Details

#bodyObject Also known as: to_s



33
34
35
# File 'lib/licensee/license.rb', line 33

def body
  @body ||= parts[2]
end

#contentObject



15
16
17
# File 'lib/licensee/license.rb', line 15

def content
  @content ||= File.open(path).read
end

#inspectObject



38
39
40
41
42
43
# File 'lib/licensee/license.rb', line 38

def inspect
  s = "#<Licensee::License name=\"#{name}\""
  s += " match=#{match}" if match
  s += ">"
  s
end

#lengthObject



29
30
31
# File 'lib/licensee/license.rb', line 29

def length
  @length ||= body.length
end

#metaObject



23
24
25
26
27
# File 'lib/licensee/license.rb', line 23

def meta
  @meta ||= front_matter = YAML.load(parts[1]) if parts[1]
rescue
  nil
end

#partsObject



19
20
21
# File 'lib/licensee/license.rb', line 19

def parts
  @parts ||= content.match /^(---\n.*\n---)?(.*)/m
end

#pathObject



11
12
13
# File 'lib/licensee/license.rb', line 11

def path
  @path ||= File.expand_path "#{@name}.txt", Licensee::Licenses.base
end