Class: Hacker::News::User

Inherits:
Struct
  • Object
show all
Defined in:
lib/hacker/news/items.rb

Overview

A HN user profile.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#aboutObject

Returns the value of attribute about

Returns:

  • (Object)

    the current value of about



125
126
127
# File 'lib/hacker/news/items.rb', line 125

def about
  @about
end

#createdObject

Returns the value of attribute created

Returns:

  • (Object)

    the current value of created



125
126
127
# File 'lib/hacker/news/items.rb', line 125

def created
  @created
end

#idString (readonly)

Returns case-sensitive username.

Returns:

  • (String)

    case-sensitive username.



125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/hacker/news/items.rb', line 125

User = Struct.new(:id, :created, :karma, :about, :submitted, keyword_init: true) do
  # @param h [Hash]
  # @return [User]
  def self.from_hash(h)
    new(
      id: h['id'],
      created: h['created'],
      karma: h['karma'],
      about: h['about'],
      submitted: h['submitted'] || []
    )
  end
end

#karmaObject

Returns the value of attribute karma

Returns:

  • (Object)

    the current value of karma



125
126
127
# File 'lib/hacker/news/items.rb', line 125

def karma
  @karma
end

#submittedObject

Returns the value of attribute submitted

Returns:

  • (Object)

    the current value of submitted



125
126
127
# File 'lib/hacker/news/items.rb', line 125

def 
  @submitted
end

Class Method Details

.from_hash(h) ⇒ User

Parameters:

  • h (Hash)

Returns:



128
129
130
131
132
133
134
135
136
# File 'lib/hacker/news/items.rb', line 128

def self.from_hash(h)
  new(
    id: h['id'],
    created: h['created'],
    karma: h['karma'],
    about: h['about'],
    submitted: h['submitted'] || []
  )
end