Class: NotionRubyMapping::TextProperty

Inherits:
Property
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable, ContainsDoesNotContain, EqualsDoesNotEqual, IsEmptyIsNotEmpty, StartsWithEndsWith
Defined in:
lib/notion_ruby_mapping/text_property.rb

Overview

Text property

Direct Known Subclasses

RichTextProperty, TitleProperty

Instance Attribute Summary collapse

Attributes inherited from Property

#name

Instance Method Summary collapse

Methods included from IsEmptyIsNotEmpty

#filter_is_empty, #filter_is_not_empty

Methods included from StartsWithEndsWith

#filter_ends_with, #filter_starts_with

Methods included from ContainsDoesNotContain

#filter_contains, #filter_does_not_contain

Methods included from EqualsDoesNotEqual

#filter_does_not_equal, #filter_equals

Methods inherited from Property

create_from_json, #make_filter_query, #type

Constructor Details

#initialize(name, will_update: false, json: nil, text_objects: nil) ⇒ TextProperty

Returns a new instance of TextProperty.

Parameters:

  • name (String)
  • json (Hash) (defaults to: nil)
  • text_objects (Array<RichTextObject>) (defaults to: nil)

Raises:

  • (StandardError)


18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/notion_ruby_mapping/text_property.rb', line 18

def initialize(name, will_update: false, json: nil, text_objects: nil)
  raise StandardError, "TextObject is abstract class.  Please use RichTextProperty." if instance_of? TextProperty

  super name, will_update: will_update
  @text_objects = if text_objects
                    text_objects.map { |to_s| RichTextObject.text_object to_s }
                  elsif json
                    json.map { |to| RichTextObject.create_from_json to }
                  else
                    []
                  end
end

Instance Attribute Details

#text_objectsObject (readonly)

Returns the value of attribute text_objects.



30
31
32
# File 'lib/notion_ruby_mapping/text_property.rb', line 30

def text_objects
  @text_objects
end

Instance Method Details

#<<(to) ⇒ NotionRubyMapping::RichTextObject

Returns added RichTextObject.

Parameters:

Returns:



47
48
49
50
51
52
# File 'lib/notion_ruby_mapping/text_property.rb', line 47

def <<(to)
  @will_update = true
  rto = RichTextObject.text_object(to)
  @text_objects << rto
  rto
end

#[](index) ⇒ RichTextObject

Returns selected RichTextObject.

Parameters:

  • index (Numeric)

    index number

Returns:



56
57
58
# File 'lib/notion_ruby_mapping/text_property.rb', line 56

def [](index)
  @text_objects[index]
end

#delete_at(index) ⇒ NotionRubyMapping::RichTextObject

Returns removed RichTextObject.

Parameters:

  • index (Numeric)

Returns:



62
63
64
65
# File 'lib/notion_ruby_mapping/text_property.rb', line 62

def delete_at(index)
  @will_update = true
  @text_objects[index]
end

#each(&block) ⇒ Enumerator

Parameters:

  • block (Proc)

Returns:

  • (Enumerator)


39
40
41
42
43
# File 'lib/notion_ruby_mapping/text_property.rb', line 39

def each(&block)
  return enum_for(:each) unless block

  @text_objects.each(&block)
end

#full_textString

Returns full_text.

Returns:

  • (String)

    full_text



68
69
70
# File 'lib/notion_ruby_mapping/text_property.rb', line 68

def full_text
  map(&:text).join ""
end

#will_updateTrueClass, FalseClass

Returns will update?.

Returns:

  • (TrueClass, FalseClass)

    will update?



33
34
35
# File 'lib/notion_ruby_mapping/text_property.rb', line 33

def will_update
  @will_update || @text_objects.map(&:will_update).any?
end