Sha256: f2f20976925ca6e8b33088606ad133a4ffe216068084980ec6b8605f60c12a1b

Contents?: true

Size: 750 Bytes

Versions: 6

Compression:

Stored size: 750 Bytes

Contents

class Licensee
  class License

    attr_reader :name
    attr_accessor :match

    def initialize(name)
      @name=name
    end

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

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

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

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

    def length
      @length ||= body.length
    end

    def body
      @body ||= parts[2]
    end
    alias_method :to_s, :body

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
licensee-0.2.0 lib/licensee/license.rb
licensee-0.1.1 lib/licensee/license.rb
licensee-0.1.0 lib/licensee/license.rb
licensee-0.0.3 lib/licensee/license.rb
licensee-0.0.2 lib/licensee/license.rb
licensee-0.0.1 lib/licensee/license.rb