Sha256: e06e4cae153e9d1f4f3b7fbdecb57e574e0ad034e0a1e9505e9ac06ebef21098

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

module Weskit::WML
  class Attribute < Item
    attachable_to :element

    attr_reader :value

    def code= bool
      @code = bool ? (@translatable = false ; true) : false
    end

    def code?
      @code
    end

    def multiline?
      "#{value}".include? "\n"
    end

    def text?
      code? or multiline? or translatable?
    end

    def translatable= bool
      @translatable = bool ? (@code = false ; true) : false
    end

    def translatable?
      @translatable
    end

    def initialize name, value, defaults = {}
      @code = @translatable = false

      self.name  = name
      self.value = value

      merge defaults
    end

    def value= object
      @value = convert object
    end

    private

    def convert object
      string = object.to_s.strip

      object = case string
        when %r{^(nil|null)$}       then nil
        when %r{^(true|yes)$}       then true
        when %r{^(false|no)$}       then false
        when %r{^[0-9]*\.[0-9]+$} then Float string
        when %r{^[0-9]+$}         then Integer string
        else string
      end

      object.attr = self ; object
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
weskit-0.3.5 lib/weskit/wml/attribute.rb
weskit-0.3.4 lib/weskit/wml/attribute.rb