Class: Fd
- Inherits:
-
Object
- Object
- Fd
- Defined in:
- lib/fd.rb,
lib/fd/version.rb
Overview
Here only the VERSION of Fd is defined All other code is in lib/fd.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- ESCAPE_CHARACTERS =
%w[␀ ␇ ␈ ␉ ␊ ␋ ␌ ␍ ␡ ␛ ␠].freeze
- CHAR_TABLE =
{ 0 => '␀', 7 => '␇', 8 => '␈', 9 => '␉', 10 => '␊', 11 => '␋', 12 => '␌', 13 => '␍', 16 => '␡', 27 => '␛', 32 => '␠' }.freeze
- VERSION =
'1.0.2'
Instance Attribute Summary collapse
-
#line_length ⇒ Object
readonly
Returns the value of attribute line_length.
Class Method Summary collapse
Instance Method Summary collapse
- #add_esc_sequence(chr) ⇒ Object
-
#dump(content) ⇒ Object
dumps the given file file_name to stdout.
- #dump_file(file_name) ⇒ Object
- #dump_stdin(content) ⇒ Object
-
#initialize(line_length) ⇒ Fd
constructor
line_length sets how many characters are displayed per @line.
Constructor Details
#initialize(line_length) ⇒ Fd
line_length sets how many characters are displayed per @line. Some special non-printable/invisible characters are displayed as their names.
- Name
-
Char val
- NULL
-
0
- BEL
-
7
- BS
-
8
- TAB
-
9
- LF
-
10
- VT
-
11
- FF
-
12
- CR
-
13
- DEL
-
16
- ESC
-
27
- __
-
32
44 45 46 47 48 49 50 51 |
# File 'lib/fd.rb', line 44 def initialize(line_length) unless line_length.is_a?(Integer) && line_length.positive? raise ArgumentError, "Line width must be a positive integer, was given '#{line_length}'" end @line_length = line_length end |
Instance Attribute Details
#line_length ⇒ Object (readonly)
Returns the value of attribute line_length.
26 27 28 |
# File 'lib/fd.rb', line 26 def line_length @line_length end |
Class Method Details
.version ⇒ Object
9 10 11 |
# File 'lib/fd/version.rb', line 9 def self.version VERSION end |
Instance Method Details
#add_esc_sequence(chr) ⇒ Object
53 54 55 |
# File 'lib/fd.rb', line 53 def add_esc_sequence(chr) "\e[31m#{chr}\e[0m" end |
#dump(content) ⇒ Object
dumps the given file file_name to stdout.
58 59 60 61 62 63 64 |
# File 'lib/fd.rb', line 58 def dump(content) raise "Not the expected encoding of UFT-8, got #{content.encoding}" unless content.encoding == Encoding::UTF_8 initialize_fields(content) process_current_character while @char_index < @chars.size print_single_line unless line.empty? end |
#dump_file(file_name) ⇒ Object
66 67 68 69 |
# File 'lib/fd.rb', line 66 def dump_file(file_name) puts file_name dump(File.read(file_name)) end |
#dump_stdin(content) ⇒ Object
71 72 73 74 |
# File 'lib/fd.rb', line 71 def dump_stdin(content) puts 'STDIN' dump(content) end |