class Propro::Export

Constants

COMMENT_RANGE
DECIMAL_RE
DQUO
EQ
EXPORT_BEGIN
INTEGER_RE
NO
SPACE_RE
SQUO
TAG_REQUIRE
TAG_SPECIFY
YES
ZERO_STRING

Public Class Methods

new(name, opts = {}) click to toggle source
# File lib/propro/export.rb, line 57
def initialize(name, opts = {})
  @name         = name.to_s.upcase
  @default      = opts[:default]
  @is_literal   = opts[:is_literal]
  @is_specified = opts[:is_specified]
  @is_required  = opts[:is_required]
  @comment      = opts[:comment]
end
parse(line) click to toggle source
# File lib/propro/export.rb, line 17
def self.parse(line)
  is_literal   = false
  is_specified = false
  is_required  = false
  comment      = nil
  line         = line.sub(EXPORT_BEGIN, ZERO_STRING)
  name, value  = line.split(EQ, 2)

  if value =~ COMMENT_RANGE
    metacomment = $1
    is_specified = true if metacomment.sub!(TAG_SPECIFY, ZERO_STRING)
    is_required  = true if metacomment.sub!(TAG_REQUIRE, ZERO_STRING)
    metacomment.strip!

    if metacomment != ZERO_STRING
      comment = metacomment
    end
  end

  value.sub!(COMMENT_RANGE, ZERO_STRING)
  value.strip!

  case value[0]
  when DQUO
    value[0]  = ZERO_STRING
    value[-1] = ZERO_STRING
  when SQUO
    is_literal = true
    value[0]   = ZERO_STRING
    value[-1]  = ZERO_STRING
  end

  new name,
    default:      value,
    is_literal:   is_literal,
    is_specified: is_specified,
    is_required:  is_required,
    comment:      comment
end

Public Instance Methods

default() click to toggle source
# File lib/propro/export.rb, line 82
def default
  cast(@default)
end
is_literal?() click to toggle source
# File lib/propro/export.rb, line 86
def is_literal?
  @is_literal
end
is_required?() click to toggle source
# File lib/propro/export.rb, line 94
def is_required?
  @is_required
end
is_specified?() click to toggle source
# File lib/propro/export.rb, line 90
def is_specified?
  @is_specified
end
key() click to toggle source
# File lib/propro/export.rb, line 66
def key
  @key ||= @name.downcase.to_sym
end
to_ruby() click to toggle source
# File lib/propro/export.rb, line 70
def to_ruby
  args = []
  args << key.inspect
  args << default.inspect
  args << "lit: true" if @is_literal
  if @comment
    "set #{args.join(', ')} # #{@comment}"
  else
    "set #{args.join(', ')}"
  end
end

Protected Instance Methods

cast(val) click to toggle source
# File lib/propro/export.rb, line 100
def cast(val)
  case val
  when INTEGER_RE
    val.to_i
  when DECIMAL_RE
    val.to_f
  when ZERO_STRING
    nil
  when SPACE_RE
    val.split(' ')
  when YES
    true
  when NO
    false
  else
    val
  end
end