Class: GroupDocs::Api::Entity
- Inherits:
-
Object
- Object
- GroupDocs::Api::Entity
- Extended by:
- Helpers::Accessor
- Defined in:
- lib/groupdocs/api/entity.rb
Direct Known Subclasses
DataSource, DataSource::Field, Document, Document::Annotation, Document::Annotation::MarkerPosition, Document::Annotation::Reply, Document::Annotation::Reviewer, Document::Change, Document::Field, Document::MetaData, Document::Page, Document::Rectangle, Document::TemplateEditorFieldOption, Document::TemplateEditorFieldStyle, Document::TemplateEditorFields, Document::View, Job, Post, Questionnaire, Questionnaire::Collector, Questionnaire::Execution, Questionnaire::Page, Questionnaire::Question, Questionnaire::Question::Answer, Questionnaire::Question::Conditions, Questionnaire::QuestionnaireCollectorStyle, Questionnaire::QuestionnaireCollectorStyle::BaseFont, Questionnaire::QuestionnaireCollectorStyle::QuestionTitle, Signature, Signature::Contact, Signature::Envelope, Signature::Envelope::Log, Signature::Field, Signature::Field::Location, Signature::Form, Signature::List, Signature::Recipient, Signature::Role, Signature::Template, Storage::File, Storage::Folder, Storage::Package, Storage::Provider, Subscription, Subscription::Limit, User, Questionnaire::QuestionnaireCollectorStyle::Title
Instance Method Summary collapse
-
#initialize(options = {}) {|self| ... } ⇒ Entity
constructor
Implements flexible API object creation.
-
#inspect ⇒ Object
private
Inspects object using accessors instead of instance variables values.
-
#to_hash ⇒ Hash
Recursively converts object and all its attributes to hash.
Methods included from Helpers::Accessor
Constructor Details
#initialize(options = {}) {|self| ... } ⇒ Entity
Implements flexible API object creation.
You can pass hash of options to automatically set attributes.
You can also pass block to set up attributes.
29 30 31 32 33 34 35 36 37 |
# File 'lib/groupdocs/api/entity.rb', line 29 def initialize( = {}, &blk) if .empty? yield self if block_given? else .each do |attr, value| send(:"#{attr}=", value) if respond_to?(:"#{attr}=") end end end |
Instance Method Details
#inspect ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Inspects object using accessors instead of instance variables values.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/groupdocs/api/entity.rb', line 74 def inspect not_nil_variables = instance_variables.select do |variable| !send(variable.to_s.underscore.delete('@')).nil? end variables = not_nil_variables.map do |variable| accessor = variable.to_s.underscore.delete('@').to_sym value = send(accessor) value = case value when Symbol then ":#{value}" when String then "\"#{value}\"" else value end "@#{accessor}=#{value}" end inspected = self.to_s unless variables.empty? inspected.gsub!(/>$/, '') inspected << " #{variables.join(', ')}" inspected << ?> end inspected end |
#to_hash ⇒ Hash
Recursively converts object and all its attributes to hash.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/groupdocs/api/entity.rb', line 49 def to_hash hash = {} instance_variables.each do |variable| key = variable.to_s.delete('@').to_sym value = instance_variable_get(variable) hash[key] = case value when GroupDocs::Api::Entity value.to_hash when Array value.map do |i| i.respond_to?(:to_hash) ? i.to_hash : i end else value end end hash end |