Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added ability to create an [Entity] with given data object.

  • Loading branch information...
commit 5397309b49c453359acd6682e9303d5dfea1062f 1 parent 34e7cc4
@jcla1 authored
Showing with 12 additions and 1 deletion.
  1. +12 −1 lib/hn2json/entity.rb
View
13 lib/hn2json/entity.rb
@@ -36,7 +36,7 @@ class Entity
attr_accessor :voting_on
- def initialize id, preserve_html=false
+ def initialize id, preserve_html=false, data={}
@id = id
@type = nil
@@ -50,6 +50,17 @@ def initialize id, preserve_html=false
@comments = nil
@votes = nil
+
+ if !data.empty?
+
+ data.keys.each do |key|
+ eval "@#{key} = data[key]"
+ end
+
+ return self
+ end
+
+
get_page
determine_type
Please sign in to comment.
Something went wrong with that request. Please try again.