Class: Pastee::Paste::Section
- Inherits:
-
Object
- Object
- Pastee::Paste::Section
- Defined in:
- lib/pastee/paste.rb
Overview
Wrapper class for paste sections.
Instance Attribute Summary collapse
-
#contents ⇒ String
readonly
Contents of the section.
-
#id ⇒ Integer
readonly
The ID for this section.
-
#name ⇒ String
readonly
The name of the section.
-
#size ⇒ Integer
readonly
Size of the section in bytes.
-
#syntax ⇒ String
readonly
The short name of the syntax used in this section.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Section
constructor
Create a new Section object.
-
#to_h ⇒ Hash
Converts this to a hash object.
Constructor Details
#initialize(opts = {}) ⇒ Section
Create a new Section object. Used when creating new pastes and when getting existing pastes. For creating new pastes, you only need to provide the name and contents and optionally syntax. The rest will be created automatically by the pastee API or by our #to_h method (syntax defaults to “autodetect”). ID and size are created by pastee, they are only here for receiving paste objects.
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/pastee/paste.rb', line 99 def initialize(opts = {}) # Standardize keys so that both the pastee API (which uses strings) and pastee-rb consumers (who use symbols) can # both use this method. opts = Hash[opts.map { |k, v| [k.to_sym, v] }] @id = opts[:id] @syntax = opts[:syntax] @name = opts[:name] @contents = opts[:contents] @size = opts[:size] end |
Instance Attribute Details
#contents ⇒ String (readonly)
Returns Contents of the section.
84 85 86 |
# File 'lib/pastee/paste.rb', line 84 def contents @contents end |
#id ⇒ Integer (readonly)
Returns The ID for this section.
75 76 77 |
# File 'lib/pastee/paste.rb', line 75 def id @id end |
#name ⇒ String (readonly)
Returns The name of the section.
81 82 83 |
# File 'lib/pastee/paste.rb', line 81 def name @name end |
#size ⇒ Integer (readonly)
Returns Size of the section in bytes.
87 88 89 |
# File 'lib/pastee/paste.rb', line 87 def size @size end |
#syntax ⇒ String (readonly)
Returns The short name of the syntax used in this section.
78 79 80 |
# File 'lib/pastee/paste.rb', line 78 def syntax @syntax end |
Instance Method Details
#to_h ⇒ Hash
Converts this to a hash object. Used in submitting pastes.
113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/pastee/paste.rb', line 113 def to_h hash = { name: name, contents: contents } hash[:id] = id if id hash[:syntax] = syntax || 'autodetect' hash[:size] = size if size hash end |