Sha256: ac825e8d0cfd20200fbd14f248c3bd2112ad3d7d1a1f6f1117217fc660f571f2

Contents?: true

Size: 863 Bytes

Versions: 6

Compression:

Stored size: 863 Bytes

Contents

class Sheet

  class Open

    attr_accessor :name

    def initialize(name)
      @name = name
    end

    def open
      if Sheet.sheet_exists?(name)
        process_sheet_content
      else
        Sheet.write "A cheat named #{name} doesn't exist.\nYou can create one with sheet new #{name}"
      end
    end

    private

    def process_sheet_content
      if contains_url_format? && cmd = Sheet.open_command
        # TODO: check if open is available
        Sheet.exec "#{cmd} #{extract_url}"
      else
        Sheet.write sheet_content
      end
    end

    def contains_url_format?
      sheet_content.split("\n").size == 1 &&
        sheet_content =~ /^url:\s*http.+$/
    end

    def extract_url
      sheet_content.match(/(http.+)$/)[1]
    end

    def sheet_content
      @sheet_content ||= File.read(Sheet.sheet_path(name))
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sheet-0.1.5 lib/sheet/open.rb
sheet-0.1.4 lib/sheet/open.rb
sheet-0.1.3 lib/sheet/open.rb
sheet-0.1.2 lib/sheet/open.rb
sheet-0.1.1 lib/sheet/open.rb
sheet-0.1.0 lib/sheet/open.rb