Sha256: 736bbad5b004d368e151b845e3721726d7a49a1307689e325bef757ebbe82209

Contents?: true

Size: 865 Bytes

Versions: 6

Compression:

Stored size: 865 Bytes

Contents

require 'memoist'

module EveOnline
  class BookmarkFolder
    extend Memoist

    attr_reader :options

    def initialize(options)
      @options = options
    end

    def as_json
      {
        folder_id: folder_id,
        folder_name: folder_name
      }
    end

    def folder_id
      options.fetch('@folderID').to_i
    end

    def folder_name
      options.fetch('@folderName')
    end

    def bookmarks
      case row
      when Hash
        [Bookmark.new(row)]
      when Array
        bookmarks = []
        row.each do |bookmark|
          bookmarks << Bookmark.new(bookmark)
        end
        bookmarks
      else
        raise ArgumentError
      end
    end
    memoize :bookmarks

    private

    def rowset
      options.fetch('rowset')
    end
    memoize :rowset

    def row
      rowset.fetch('row')
    end
    memoize :row
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
eve_online-0.14.0 lib/eve_online/bookmark_folder.rb
eve_online-0.13.0 lib/eve_online/bookmark_folder.rb
eve_online-0.12.0 lib/eve_online/bookmark_folder.rb
eve_online-0.11.0 lib/eve_online/bookmark_folder.rb
eve_online-0.10.0 lib/eve_online/bookmark_folder.rb
eve_online-0.9.0 lib/eve_online/bookmark_folder.rb