Sha256: 3e32a5add50ae50c3f41ffc02e40149a98616cacc0dfe4a2841f85e9e0b97e28

Contents?: true

Size: 628 Bytes

Versions: 2

Compression:

Stored size: 628 Bytes

Contents

module SimplestStatus
  class Status
    attr_reader :name, :value

    def initialize(input)
      @name, @value = Array(input)
    end

    def symbol
      name.to_sym
    end

    def string
      name.to_s
    end
    alias :to_s :string

    def to_hash
      { name => value }
    end

    def matches?(input)
      [string, value.to_s].include? input.to_s
    end

    def constant_name
      string.upcase
    end

    def label
      string.split(/[\s_-]+/).map(&:capitalize).join(' ')
    end

    def for_select
      [label, value]
    end

    def ==(status)
      self.to_hash == status.to_hash
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
simplest_status-1.0.0 lib/simplest_status/status.rb
simplest_status-0.1.0 lib/simplest_status/status.rb