Class: ClassMetrix::Extractor

Inherits:
Object
  • Object
show all
Defined in:
lib/class_metrix/extractor.rb

Instance Method Summary collapse

Constructor Details

#initialize(*types) ⇒ Extractor

Returns a new instance of Extractor.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/class_metrix/extractor.rb', line 13

def initialize(*types)
  @types = types.flatten
  @classes = []
  @filters = []
  @expand_hashes = false
  @handle_errors = false
  # New default: comprehensive scanning (inheritance + modules enabled by default)
  @include_inherited = true
  @include_modules = true
  @include_private = false # Private still requires explicit opt-in
  @show_source = false
  @hide_main_row = false
  @hide_key_rows = true # Default: show only main rows
  @debug_mode = false
  @debug_level = :basic
  @logger = nil # Will be initialized when debug mode is enabled
end

Instance Method Details

#debug(level = :basic) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/class_metrix/extractor.rb', line 48

def debug(level = :basic)
  @debug_mode = true
  @debug_level = level
  @logger = Utils::DebugLogger.new("Extractor", @debug_mode, level)
  @logger&.log("Debug mode enabled (level: #{level})")
  self
end

#expand_hashesObject



42
43
44
45
46
# File 'lib/class_metrix/extractor.rb', line 42

def expand_hashes
  @expand_hashes = true
  @logger&.log("Hash expansion enabled")
  self
end

#filter(pattern) ⇒ Object



37
38
39
40
# File 'lib/class_metrix/extractor.rb', line 37

def filter(pattern)
  @filters << pattern
  self
end

#from(classes) ⇒ Object



31
32
33
34
35
# File 'lib/class_metrix/extractor.rb', line 31

def from(classes)
  @classes = ClassResolver.normalize_classes(classes)
  @logger&.log("Normalized classes: #{@classes.map(&:name)}")
  self
end

#handle_errorsObject



56
57
58
59
# File 'lib/class_metrix/extractor.rb', line 56

def handle_errors
  @handle_errors = true
  self
end

#hide_key_rowsObject



105
106
107
108
# File 'lib/class_metrix/extractor.rb', line 105

def hide_key_rows
  @hide_key_rows = true
  self
end

#hide_main_rowObject

Lower-level options (for advanced usage)



100
101
102
103
# File 'lib/class_metrix/extractor.rb', line 100

def hide_main_row
  @hide_main_row = true
  self
end

#show_expanded_detailsObject



93
94
95
96
97
# File 'lib/class_metrix/extractor.rb', line 93

def show_expanded_details
  @hide_main_row = false
  @hide_key_rows = false
  self
end

#show_only_keysObject



87
88
89
90
91
# File 'lib/class_metrix/extractor.rb', line 87

def show_only_keys
  @hide_main_row = true
  @hide_key_rows = false
  self
end

#show_only_mainObject

Hash expansion display options



81
82
83
84
85
# File 'lib/class_metrix/extractor.rb', line 81

def show_only_main
  @hide_main_row = false
  @hide_key_rows = true
  self
end

#show_sourceObject



75
76
77
78
# File 'lib/class_metrix/extractor.rb', line 75

def show_source
  @show_source = true
  self
end

#strictObject

Clean modern API methods



62
63
64
65
66
67
# File 'lib/class_metrix/extractor.rb', line 62

def strict
  @include_inherited = false
  @include_modules = false
  @logger&.log("Strict mode enabled - scanning class only")
  self
end

#to_csv(filename = nil, **options) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/class_metrix/extractor.rb', line 138

def to_csv(filename = nil, **options)
  @logger&.log("Starting CSV generation...")
  data = extract_all_data

  format_options = {
    extraction_types: @types,
    show_metadata: true,
    separator: ",",
    quote_char: '"',
    flatten_hashes: true,
    null_value: "",
    comment_char: "#",
    hide_main_row: @hide_main_row,
    hide_key_rows: @hide_key_rows,
    debug_mode: @debug_mode,
    debug_level: @debug_level
  }.merge(options)

  formatted = CsvFormatter.new(data, @expand_hashes, format_options).format

  File.write(filename, formatted) if filename
  formatted
end

#to_markdown(filename = nil, **options) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/class_metrix/extractor.rb', line 110

def to_markdown(filename = nil, **options)
  @logger&.log("Starting markdown generation...")
  data = extract_all_data
  @logger&.log("Extracted data structure with #{data[:rows]&.length || 0} rows")

  format_options = {
    extraction_types: @types,
    show_missing_summary: false,
    show_footer: true,
    footer_style: :default,
    show_timestamp: false,
    show_metadata: true,
    show_classes: true,
    show_extraction_info: true,
    table_style: :standard,
    summary_style: :grouped,
    hide_main_row: @hide_main_row,
    hide_key_rows: @hide_key_rows,
    debug_mode: @debug_mode,
    debug_level: @debug_level
  }.merge(options)

  formatted = MarkdownFormatter.new(data, @expand_hashes, format_options).format

  File.write(filename, formatted) if filename
  formatted
end

#with_privateObject



69
70
71
72
73
# File 'lib/class_metrix/extractor.rb', line 69

def with_private
  @include_private = true
  @logger&.log("Private scanning enabled")
  self
end