ntcharts 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/ntcharts.rb CHANGED
@@ -2,7 +2,101 @@
2
2
 
3
3
  require_relative "ntcharts/version"
4
4
 
5
+ begin
6
+ major, minor, _patch = RUBY_VERSION.split(".")
7
+ require_relative "ntcharts/#{major}.#{minor}/ntcharts"
8
+ rescue LoadError
9
+ require_relative "ntcharts/ntcharts"
10
+ end
11
+
12
+ require_relative "ntcharts/bar_data"
13
+
5
14
  module Ntcharts
6
15
  class Error < StandardError; end
7
- # Your code goes here...
16
+
17
+ # Helper method to convert Lipgloss::Style to Ntcharts::Style
18
+ # This allows using Lipgloss::Style objects directly with ntcharts
19
+ def self.convert_style(style)
20
+ return style if style.is_a?(Ntcharts::Style)
21
+
22
+ raise ArgumentError, "Expected Ntcharts::Style or Lipgloss::Style, got #{style.class}" unless style.respond_to?(:get_foreground) && style.respond_to?(:get_background) && style.respond_to?(:bold?)
23
+
24
+ ntcharts_style = Ntcharts::Style.new
25
+
26
+ fg = style.get_foreground
27
+ bg = style.get_background
28
+
29
+ ntcharts_style = ntcharts_style.foreground(fg) if fg
30
+ ntcharts_style = ntcharts_style.background(bg) if bg
31
+ ntcharts_style = ntcharts_style.bold(style.bold?) if style.bold?
32
+
33
+ ntcharts_style
34
+ end
35
+
36
+ module StyleSetters
37
+ def style=(value)
38
+ _set_style(Ntcharts.convert_style(value))
39
+ end
40
+
41
+ def axis_style=(value)
42
+ _set_axis_style(Ntcharts.convert_style(value))
43
+ end
44
+
45
+ def label_style=(value)
46
+ _set_label_style(Ntcharts.convert_style(value))
47
+ end
48
+ end
49
+
50
+ class Barchart
51
+ include StyleSetters
52
+
53
+ def push(bar_data)
54
+ data = case bar_data
55
+ when BarData then bar_data
56
+ when Hash then BarData.new(**bar_data)
57
+ else raise ArgumentError, "Expected BarData or Hash"
58
+ end
59
+
60
+ _push(data)
61
+
62
+ self
63
+ end
64
+
65
+ def push_all(bar_data_array)
66
+ data = bar_data_array.map do |d|
67
+ case d
68
+ when BarData then d
69
+ when Hash then BarData.new(**d)
70
+ else raise ArgumentError, "Expected BarData or Hash"
71
+ end
72
+ end
73
+ _push_all(data)
74
+ self
75
+ end
76
+
77
+ def render
78
+ draw
79
+ view
80
+ end
81
+ end
82
+
83
+ class Sparkline
84
+ include StyleSetters
85
+ end
86
+
87
+ class Linechart
88
+ include StyleSetters
89
+ end
90
+
91
+ class Wavelinechart
92
+ include StyleSetters
93
+ end
94
+
95
+ class Streamlinechart
96
+ include StyleSetters
97
+ end
98
+
99
+ class Timeserieslinechart
100
+ include StyleSetters
101
+ end
8
102
  end
data/ntcharts.gemspec CHANGED
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
30
30
  ]
31
31
 
32
32
  spec.require_paths = ["lib"]
33
+ spec.extensions = ["ext/ntcharts/extconf.rb"]
33
34
 
34
35
  spec.add_dependency "rake-compiler", "~> 1.2"
35
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ntcharts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Roth
@@ -27,11 +27,32 @@ description: Ruby wrapper for NimbleMarkets' ntcharts terminal charting library.
27
27
  email:
28
28
  - marco.roth@intergga.ch
29
29
  executables: []
30
- extensions: []
30
+ extensions:
31
+ - ext/ntcharts/extconf.rb
31
32
  extra_rdoc_files: []
32
33
  files:
33
34
  - README.md
35
+ - ext/ntcharts/barchart.c
36
+ - ext/ntcharts/extconf.rb
37
+ - ext/ntcharts/extension.c
38
+ - ext/ntcharts/extension.h
39
+ - ext/ntcharts/linechart.c
40
+ - ext/ntcharts/sparkline.c
41
+ - ext/ntcharts/streamlinechart.c
42
+ - ext/ntcharts/style.c
43
+ - ext/ntcharts/timeserieslinechart.c
44
+ - ext/ntcharts/wavelinechart.c
45
+ - go/barchart.go
46
+ - go/go.mod
47
+ - go/go.sum
48
+ - go/linechart.go
49
+ - go/ntcharts.go
50
+ - go/sparkline.go
51
+ - go/streamlinechart.go
52
+ - go/timeserieslinechart.go
53
+ - go/wavelinechart.go
34
54
  - lib/ntcharts.rb
55
+ - lib/ntcharts/bar_data.rb
35
56
  - lib/ntcharts/version.rb
36
57
  - ntcharts.gemspec
37
58
  homepage: https://github.com/marcoroth/ntcharts-ruby