Sha256: fba1ee04bc46f9362a08758171ccfc5790fef1e1b7ef5e0b9eb4876fbc497643

Contents?: true

Size: 975 Bytes

Versions: 2

Compression:

Stored size: 975 Bytes

Contents

module Copy
  class Base
    include Copy::Operations::Base

    attr_accessor :created_time

    # Initializes the object using the given attributes
    #
    # @param [Hash] attributes The attributes to use for initialization
    def initialize(attributes = {})
      set_attributes(attributes)
      parse_timestamps
    end

    # Model validations
    #
    # @return [Boolean]
    def valid?
      self.errors.empty?
    end

    # Accesor for the errors
    #
    def errors
      @errors || []
    end

    # Sets the attributes
    #
    # @param [Hash] attributes The attributes to initialize
    def set_attributes(attributes)
      attributes.each_pair do |key, value|
        instance_variable_set("@#{key}", value)
      end
    end

    # Parses UNIX timestamps and creates Time objects.
    def parse_timestamps
      @created_time = created_time.to_i if created_time.is_a? String
      @created_time = Time.at(created_time) if created_time
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
copy-ruby-0.0.2 lib/copy/base.rb
copy-ruby-0.0.1 lib/copy/base.rb