Sha256: faa6bebf1ab594e8d23d56ad85b2cad27db1f8b5305616ec212468c68dc14a38

Contents?: true

Size: 841 Bytes

Versions: 3

Compression:

Stored size: 841 Bytes

Contents

module CoderWally
  # Builds the CoderWall object from the response
  class Builder
    # Instantiate class
    def initialize
    end

    # parse badges from data
    def parse_badges(badges)
      badges.map { |badge| create_new_badge(badge) } if badges
    end

    # create a new badge object
    def create_new_badge(badge)
      Badge.new(badge)
    end

    # parse account information from data
    def parse_accounts(accounts)
      Account.new(accounts) if accounts
    end

    # parse user information from data
    def parse_user(data)
      badges = parse_badges(data['badges'])
      accounts = parse_accounts(data['accounts'])
      User.new(data, badges, accounts)
    end

    # build CoderWall object from API response
    def build(response)
      user = parse_user(response)

      CoderWall.new user
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
coder_wally-1.0.2 lib/coder_wally/builder.rb
coder_wally-1.0.1 lib/coder_wally/builder.rb
coder_wally-1.0.0 lib/coder_wally/builder.rb