Class: Gloo::Objs::Text
- Inherits:
-
Core::Obj
- Object
- Core::Baseo
- Core::Obj
- Gloo::Objs::Text
- Defined in:
- lib/gloo/objs/basic/text.rb
Constant Summary collapse
- KEYWORD =
'text'.freeze
- KEYWORD_SHORT =
'txt'.freeze
- DEFAULT_TMP_FILE =
'tmp.txt'.freeze
Instance Attribute Summary
Attributes inherited from Core::Obj
Attributes inherited from Core::Baseo
Class Method Summary collapse
-
.messages ⇒ Object
Get a list of message names that this object receives.
-
.short_typename ⇒ Object
The short name of the object type.
-
.typename ⇒ Object
The name of the object type.
Instance Method Summary collapse
-
#line_count ⇒ Object
Get the number of lines of text.
-
#msg_edit ⇒ Object
Edit the text in the default editor.
-
#msg_page ⇒ Object
Show the contents of the file, paginated.
-
#multiline_value? ⇒ Boolean
Does this object support multi-line values? Initially only true for scripts.
-
#set_value(new_value) ⇒ Object
Set the value with any necessary type conversions.
Methods inherited from Core::Obj
#add_child, #add_children_on_create?, #add_default_children, can_create?, #can_receive_message?, #child_count, #contains_child?, #delete_children, #dispatch, #display_value, #find_add_child, #find_child, help, inherited, #initialize, #msg_unload, #pn, #remove_child, #root?, #send_message, #set_parent, #type_display, #value_display, #value_is_array?, #value_is_blank?, #value_string?
Methods inherited from Core::Baseo
Constructor Details
This class inherits a constructor from Gloo::Core::Obj
Class Method Details
.messages ⇒ Object
Get a list of message names that this object receives.
60 61 62 |
# File 'lib/gloo/objs/basic/text.rb', line 60 def self. return super + %w[edit page] end |
.short_typename ⇒ Object
The short name of the object type.
27 28 29 |
# File 'lib/gloo/objs/basic/text.rb', line 27 def self.short_typename return KEYWORD_SHORT end |
.typename ⇒ Object
The name of the object type.
20 21 22 |
# File 'lib/gloo/objs/basic/text.rb', line 20 def self.typename return KEYWORD end |
Instance Method Details
#line_count ⇒ Object
Get the number of lines of text.
49 50 51 |
# File 'lib/gloo/objs/basic/text.rb', line 49 def line_count return value.split( "\n" ).count end |
#msg_edit ⇒ Object
Edit the text in the default editor.
78 79 80 81 82 83 |
# File 'lib/gloo/objs/basic/text.rb', line 78 def msg_edit tmp = File.join( $settings.tmp_path, DEFAULT_TMP_FILE ) File.open( tmp, 'w' ) { |file| file.write( self.value ) } TTY::Editor.open( tmp ) set_value File.read( tmp ) end |
#msg_page ⇒ Object
Show the contents of the file, paginated.
67 68 69 70 71 72 73 |
# File 'lib/gloo/objs/basic/text.rb', line 67 def msg_page return unless value # pager = TTY::Pager::SystemPager.new command: 'less -R' pager = TTY::Pager.new pager.page( value ) end |
#multiline_value? ⇒ Boolean
Does this object support multi-line values? Initially only true for scripts.
42 43 44 |
# File 'lib/gloo/objs/basic/text.rb', line 42 def multiline_value? return false end |
#set_value(new_value) ⇒ Object
Set the value with any necessary type conversions.
34 35 36 |
# File 'lib/gloo/objs/basic/text.rb', line 34 def set_value( new_value ) self.value = new_value.to_s end |