Sha256: 08cb17db98c1b67400ef3cd95052663e72f36c64528fe70633947e0598c62720

Contents?: true

Size: 842 Bytes

Versions: 7

Compression:

Stored size: 842 Bytes

Contents

module TryApi
  class Project < TryApi::Base
    typesafe_accessor :name, String
    typesafe_accessor :menu_items, Array
    typesafe_accessor :host, String
    typesafe_accessor :port, Integer
    typesafe_accessor :api_prefix, String

    class << self
      def parse(hash)
        instance = self.new
        instance.name = hash[:project_name]
        instance.host = hash[:host]
        instance.port = hash[:port]
        instance.api_prefix = hash[:api_prefix]
        instance.menu_items = []
        hash[:menu_items].each do |category|
          instance.menu_items << TryApi::MenuItem.parse(hash: category, project: instance)
        end
        instance
      end
    end

    def to_json
      super.merge endpoint: endpoint
    end

    def endpoint
      "#{ host }#{ port.blank? ? '' : (':' + port.to_s) }"
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
try_api-0.0.12 app/models/try_api/project.rb
try_api-0.0.11 app/models/try_api/project.rb
try_api-0.0.10 app/models/try_api/project.rb
try_api-0.0.9 app/models/try_api/project.rb
try_api-0.0.8 app/models/try_api/project.rb
try_api-0.0.7 app/models/try_api/project.rb
try_api-0.0.6 app/models/try_api/project.rb